The major system is a mnemonic device for converting numbers into words so they can be memorized more easily.
It is based on how words sound phonetically, but to keep things simple for the challenge we'll only be concerned with how words are spelled. This means there will be some incorrect conversions, but that's alright.
To convert a number into a word using our simplified major system:
- Replace each
0
withs
orz
. (Some could bes
and some could bez
. Same goes below.)- Replace each
1
witht
ord
orth
.- Replace each
2
withn
.- Replace each
3
withm
.- Replace each
4
withr
.- Replace each
5
withl
.- Replace each
6
withj
orsh
orch
.- Replace each
7
withk
orc
org
orq
.- Replace each
8
withf
orv
.- Replace each
9
withp
orb
.- Add the letters
aehiouwxy
anywhere in any amounts to make a real English word, if possible.
The only exception is thath
may not be inserted after ans
orc
.The number may actually be any string of the digits 0-9 (no decimals or commas or signs).
The word can only contain the lowercase letters a-z.
##Examples
The number 32
must be converted as ?m?n?
, where ?
represents any finite string made from the letters aehiouwxy
(a string from the free monoid if you prefer). There are many ways this could be made into a real English word: mane
, moon
, yeoman
, etc.
The number 05
could be converted as ?s?l?
or ?z?l?
. Some possibilities are easily
, hassle
, and whistle
. The word shawl
is not allowed because h
may not be placed after s
; it would be incorrectly read as 65
.
#Challenge
Write a program or function that takes in a string of the digits 0-9 and finds all the words that it could be converted into using the simplified major system mnemonic.
Your program has access to a word list text file that defines what all the "real" English words are. There is one lowercase a-z word on each line of this file, and you may optionally assume it has a trailing newline. Here is a list of real words you can use for testing. You can assume this word list file is called f
(or something longer) and lies in any convenient directory.
Your program must output all the words in the word list that the input number can be converted to. They should be printed to stdout (or similar), one per line (with an optional trailing newline), or they can be returned as a list of strings if you chose to write a function. The word list is not necessarily alphabetized and the output doesn't need to be either.
If there are no possible words then the output (or the list) will be empty. The output is also empty if the empty string is input.
Take input via stdin, command line, or as a string argument to a function. The word list file name should not be part of the input, only the digit string.
You are only matching single words in the word list, not sequences of words. The word noon
would probably be one of the results for 22
, but the word sequence no one
wouldn't.
##Test Cases
Suppose this is the word list:
stnmrljkfp
zthnmrlshqfb
asatanamaralajakafapa
aizxydwwwnhimouooraleshhhcavabe
zdnmrlshcvb
zdnmrlshchvb
sthnmrlchgvb
shthnmrlchgvb
bob
pop
bop
bopy
boppy
The input 0123456789
should give all the long words except zdnmrlshchvb
and shthnmrlchgvb
:
stnmrljkfp
zthnmrlshqfb
asatanamaralajakafapa
aizxydwwwnhimouooraleshhhcavabe
zdnmrlshcvb
sthnmrlchgvb
The input 99
should give:
bob
pop
bop
bopy
(The output words may be in any order.)
##Scoring
The shortest submission in bytes wins. Tiebreaker goes to the submission posted first.
Nifty related site: numzi.com.