The Monthly Course: String to Number


Goal

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.


Specification

The program is a filter: it must read from STDIN, and send output to STDOUT.


Tiebreaker

The tiebreaker will favour programs with fewer alphanumeric and whitespace characters.


General rules


Examples

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

Deadline

The game starts October 5th (05:00 UTC) and ends October 12th (05:00 UTC).


Test program

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.


Submitting

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.


Leaderboard

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.


Feedback

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 (golf@perl.org). Don't mail the ideas themselves!


Referees