import "listUtil" import "mapUtil" groups = "abc def ghi jkl mno pqrs tuv wxyz".split charToNum = {} for i in groups.indexes for ch in groups[i] charToNum[ch] = i + 2 end for end for words = file.readLines("/sys/data/englishWords.txt") wordToNum = function(word) parts = word.split("") parts.apply function(ch) return charToNum[ch] end function return parts.join("") end function numToWords = {} moreThan1Word = 0 for word in words num = wordToNum(word.lower) if numToWords.hasIndex(num) then numToWords[num].push word else numToWords[num] = [word] end if if numToWords[num].len == 2 then moreThan1Word = moreThan1Word + 1 end for print "There are " + words.len + " words in englishWords.txt which can be represented by the digit key mapping." print "They require " + numToWords.len + " digit combinations to represent them." print moreThan1Word + " digit combinations represent Textonyms." while true print inp = input("Enter a word or digit combination: ") if not inp then break if val(inp) > 0 then print inp + " -> " + numToWords.get(inp) else num = wordToNum(inp.lower) print "Digit key combination for """ + inp + """ is: " + num print num + " -> " + numToWords.get(num) end if end while