What is Codegolf, and how do I play?
Based on the original perl golf, Codegolf allows you to show off your code-fu and try and solve coding problems using the least number of keystrokes.
You're not just limited to Perl either - PHP, Python and Ruby are all available too.
Challenges are always open, and your entries are automatically scored so you can start playing right away!
To play, simply choose a challenge that you want to enter.
In most challenges, your code will have to match some given output. Depending on the challenge, your code may have to take some input and provide output accordingly. Read the challenge instructions carefully, all the information you need will be included.
Write your code in any of the supported languages, and once you are happy that it works correctly, upload it.
Your code will be automatically executed and checked by our system. If your code matches the output we were expecting, you will receive a score and hopefully a place on the leaderboard.
If your code doesn't match the output, or the code fails for other reasons (Syntax errors, or it took it long to execute), your code will be marked as failed. Don't worry if this happens though, you're not penalised for entries that fail! If it does fail, click on the "failed" link, and using the information on that page, try and fix your code.
Now your code is working, and unless your first attempt was the smallest possible, you will probably want to make it smaller. You can only upload new entries every 2 minutes, but you can upload as many entries as you want. Remember, the user who gets to a certain code size first will be placed above users who get there later - So submit early, and submit often!
If you believe you've cracked the challenge in one language, why not try it in another? You can enter each challenge will all the languages, if you want.
Which languages are available, and which versions are you running?
Codegolf supports Perl, PHP, Python and Ruby. The versions are as follows :
- Perl 5.8.8
- PHP 5.2.1
- Python 2.5
- Ruby 1.8.5 (2006-12-25 patchlevel 12)
All languages will be kept relatively up to date as new versions are released.
What are the rules for entering?
You can upload any code that you believe will fulfill the requirements of the challenge. There are no requirements on how you format your code in terms of line length or number of lines. You can enter all challenges, and you can enter them using all of the available languages if you want to.
There are a couple of restrictions that may affect you :
- You can only submit an entry every 2 minutes.
- You can only upload files which are equal to or smaller than 51,200 bytes in size.
- You will be unable to import/require/include any modules or files in your solution. You have to write all the code yourself, and it has to be in the code file you upload.
There are a couple of things about your code's execution that might be useful to know :
- Execution of your code will stop after 4 seconds of wall time. Any code which is stopped in this manner will be deemed to have failed.
- Trailing whitespace from your output and the reference output you are trying to match will be stripped when they are being compared.
How does the scoring work?
Scoring is performed per-challenge with a maximum score of 10,000 available. The scoring works using the following formula :
10000 * ( best_code_size / your_best_code_size )
best_code_size is the smallest working entry submitted for the challenge by all users, and
your_best_code_size is your smallest working entry. All code sizes are measured in bytes and you are not penalised for entries that fail.
The per-language leaderboards are calculated in a similar way by taking only solutions in the given language into account. Therefore, you can enter each challenge in each of the available languages - You will receive a separate score for each of them, and your shortest solution across all languages will be used in the overall leaderboard.
The overall leaderboards are merely the summation of the points each user has gained in the challenges they have entered.
In the event of two or more people being level on points, we use other information to decide how to order them in the leaderboard. On the overall leaderboard, the person who has entered the least number of challenges will be placed first. On the individual challenge leaderboards, the person who first submitted their entry at that code size will be placed first.
On challenge pages, the number of attempts are listed beside the user's score. For example, “10,000 (v5)” indicates that the user has attempted the challenge five times.