Textonyms: Difference between revisions

No edit summary
Line 64:
=={{header|Ruby}}==
<lang ruby>
TextonymesTextonyms = Hash.new {|n, g| n[g] = [] }
File.open("Textonyms.txt") do |file|
file.each_line {|line|
TextonymesTextonyms[(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>
{{out}}
<pre>
puts "There are #{Textonyms.inject(0){|n,g| n+g[1].length}} words in #{"http://rosettacode.org/wiki/Textonyms/wordlist"} which can be represnted by the Textonyms mapping."
puts "They require #{Textonyms.length} digit combinations to represent them."
 
There are 132916 words in http://rosettacode.org/wiki/Textonyms/wordlist which can be represnted by the Textonyms mapping.
They require 117868 digit combinations to represent them.
</pre>
<pre>
puts Textonymes["7353284667"]
2,172

edits