Your program will receive one number on the standard input, written out, e.g. 'one', 'two' or 'sixteen thousand'. It should convert this string to a number, and write it to the standard output.
The program is a filter: it must read from STDIN, and send output to STDOUT.
Input will consist of a single line, which will match
/\A[a-z]+( [a-z]+)*\n\z/. This means that the input will
consist of one or more words seperated by single spaces, and each word will
only contain lowercase letters.
The input will be an American-English name of a whole number between
nine hundred ninety nine billion nine
hundred ninety nine million nine hundred ninety nine thousand nine
hundred ninety nine. These numbers will satisfy the following
billionare separate words. They are always preceded by a lower number (for example
one hundred), never by the word 'a'.
billionis a thousand millions, 10**9.
ninety nineare not hyphenated. This also holds for compound numbers like
twenty one thousand.
one thousandwill not be written as multiple of 100:
nineteen hundredis invalid input.
andis not used.
The output should be a single line, matching
/\a[,\d]+\n\z/, and be the numerical representation of the
input number. The digits should be separated in groups of three by
commas, starting at the back.
The tiebreaker will favour programs with fewer alphanumeric and whitespace characters.
You must not write to STDERR.
The program return code does not matter.
The program's runtime should be reasonably short. For any valid input the program should run in five minutes of CPU time on a 600 MHz Celeron.
The programs can be written as one or more lines. The score is the total number of bytes you need (smaller is better). If your program is more than one line, you must count the newlines in between as one character each. The #! line is not counted. If you use options on the #! line, the options themselves are counted, including the leading space and ``-''.
If two (or more) golfers have the same score for the hole, the golfer with the lowest tie break score wins.
All programs must work on perl 5.6.1.
Assume total memory is < 2**32 bytes.
The programs may only use the perl executable, no other executables on the system are allowed (the program may use itself though). You may not use any modules, except for the pragmas (modules starting with a lower case letter) that come with perl 5.6.1. Your solutions must be portable in the sense that it should work on all versions of 5.6.1 everywhere (however, it's perfectly fine to abuse perl 5.6.1 bugs).
When tested, your script will be named strtol.pl, and you must assume your script to have file permissions of 0444 (that is read-only and non-executable for windows folks).
At least 75% of your script should consist of readable characters
(contained in the character class
input: zero output: 0 input: eight output: 8 input: twenty four output: 24 input: one hundred sixty output: 160 input: twelve million three hundred thousand output: 12,300,000
The game starts October 5th (05:00 UTC) and ends October 12th (05:00 UTC).
A test program (version 4 now available) is provided to help screen entries.
Any program that passes the test program should be submitted. If you are surprised that your solution passed the test program, please submit it anyway! That will help us identify bugs in the test program.
Name your script strtol.pl, and place it in the same directory as your test program. Then verify and score your attempt using:
$ perl tpr05b.pl
The test program is based on Ton Hospel's generic golf tester, and thus has plenty of useful features. For more information on them type:
$ perl tpr05b.pl --help
Passing the test program does not assure your solution is valid. The referees have the final say.
You can submit your solutions here (you'll notice it's the same page as the Leaderboard). As a courtesy to other players, you should not wait until the last moment to submit your solutions. Everyone has more fun when the leaderboard depicts the situation correctly.
Do not publish your solutions anywhere. That will spoil the game, as your solutions are meant to be secret. All solutions will be published at the end of the game.
Prizes (provided by O'Reilly and ActiveState) will be awarded to veteran and beginner winners. A prize may also be awarded to any especially interesting artistic and/or unorthodox solutions.
You can track your ranking through the leaderboard here. Beginners are encouraged to enter and there is a separate leaderboard for them.
There is also a special leaderboard for teams. There will be no prizes awarded to the best team, other than the admiration of your fellow golfers. If you are in a team, you can't also play individually.
We encourage you to send feedback on this hole the referees. If you have ideas for future holes, or if you want to be a referee next month, let us know via the perl golf mailing list (email@example.com). Don't mail the ideas themselves!
Ala Qumsieh <firstname.lastname@example.org>
Geoff Hubbard <email@example.com>
Jasper McCrea <firstname.lastname@example.org>
Eugène van der Pijll <email@example.com>