The Rules
It's time to build a typing speed test in your language of choice!
1. You provide a file with a dictionary of choice (every 'word' in it must be newline delimited). Pipe it in via stdin
or provide it's name as a command line argument.
a able about above absence ...
2. Pick 10 random words from the file (no duplicates must be allowed) and print them out in the following manner:
-> direct -> ground -> next -> five ...
3. Start measuring the time spent from now on!
4. Let the user type all of the ten words as fast as possible (ended with a carriage return). Print OK
when you have a match, print WRONG
when we have a typing mistake (or the word was already succesfully typed in this run).
5. Stop the clocks! Now print the CPM (Caracters per minute) benchmark, which is calculated as follows: (sum of the characters of the chosen words / time spent typing (seconds)) * 60
. Round to the nearest integer and reproduce the following (sample) output:
--> You have scored 344 CPM!
A sample run
-> settle -> side -> open -> minister -> risk -> color -> ship -> same -> size -> sword settle OK side OK open OK # ...................... some lines snipped ...................... word WRONG sword OK --> You have scored 298 CPM!
The winner
This is code colf, the shortest entry (in source code character count) wins, have fun!