Textonyms
Textonyms is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.
When entering text on a phone's digital pad it is possible that a particular combination of digits corresponds to more than one word. Such are called textonyms.
Assuming the keys are as follows:
2 -> ABC 3 -> DEF 4 -> GHI 5 -> JKL 6 -> MNO 7 -> PQRS 8 -> TUV 9 -> WXYZ
The task is to write a program that finds textonyms in this list of words Textonyms/wordlist
Extra credit:
Use a word list and keypad mapping other than English.
Ruby
<lang ruby>
- Textonyms: Nigel Galloway February 4th., 2015.
Textonymes = Hash.new {|n, g| n[g] = [] } File.open("Textonyms.txt") do |file|
file.each_line {|line| Textonymes[(n=line.chomp).gsub(/a|b|c|A|B|C/, '2').gsub(/d|e|f|D|E|F/, '3').gsub(/g|h|i|G|H|I/, '4').gsub(/p|q|r|s|P|Q|R|S/, '7') .gsub(/j|k|l|J|K|L/, '5').gsub(/m|n|o|M|N|O/, '6').gsub(/t|u|v|T|U|V/, '8').gsub(/w|x|y|z|W|X|Y|Z/, '9')] += [n] }
end </lang>
- Output:
puts Textonymes["7353284667"] rejections selections
puts Textonymes["736672"] #remora #senora