this challenge was based on a sandboxed post by @dmckee
Old fashioned cell phones were and are used heavily as texting platforms, unfortunately the keyboard has only 12 + a few buttons, and is therefor ill-suited to naive text entry.
Common solutions make use of the traditional telephone coding (generally with a modest extension for 'q' and 'z'):
2: a,b,c 3: d,e,f 4: g,h,i 5: j,k,l 6: m,n,o 7: p(,q),r,s 8: t,u,v 9: w,x,y(,z)
In this case we are interested in the one-press-per-letter schemes that offer up words matching words on a frequency basis. That is if the user type "4663" the phone will offer up words like "good", "home", "gone", "hood", "hoof", etc that code to 4663 in order of their frequency.
Your task is to read one or more input files and generate a frequency sorted dictionary that could be used to implement this scheme.
- All input will be plain ASCII text.
- You may accept input from named files, the standard input, or other conventional source supported by your implementation language, but there must be some mechanism to process several files in a single run.
- Non-letter, non-whitespace characters should be stripped from the input, this means that contractions will be coded without their apostrophe:
"don't" --> "dont" --> 3668
- Words are a sequence of letters separated surrounded by whitespace
- All whitespace (space, tab, newline, beginning-of-file, end-of-file) is equivalent.
- Input will be all lowercase or caps your preference.
- The output consists of a ASCII text stream
- You may direct this to a file, the standard output, or any other conventional destination supported by your implementation language
- The output should consist of one line for each string of digits corresponding to at least one word in the input.
Each line should consist of the digit string and a list of all corresponding words sorted by frequency with the most frequent coming first. A sample line of output would be
4663 good home gone hood hoof
Tokens (digit strings and corresponding words) should be separated by a single space.
- Equally frequent words may be sorted in any order.
The winner is the shortest code.
potato, potato, damd, fjefje, djfaejri Top 1000 words used. The potato was a down goat goat down game gill pont pint point.
More actual test cases will be given in about a week to prevent any sort of hard-coding action.