Textonyms: Difference between revisions
Content added Content deleted
m (→{{header|Phix}}: added syntax colouring, use of unix_dict(), multiple max_idx, and longest words) |
(→{{header|Ruby}}: use tr and group_by) |
||
Line 2,747: | Line 2,747: | ||
=={{header|Ruby}}== |
=={{header|Ruby}}== |
||
<lang ruby> |
<lang ruby> |
||
CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" |
|||
Textonyms = Hash.new {|n, g| n[g] = []} |
|||
NUMS = "22233344455566677778889999"*2 |
|||
File.open("Textonyms.txt") do |file| |
|||
dict = "unixdict.txt" |
|||
file.each_line {|line| |
|||
Textonyms[(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') |
|||
textonyms = File.open("unixdict.txt"){|f| f.map(&:chomp).group_by {|word| word.tr(CHARS, NUMS) } } |
|||
.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 |
|||
⚫ | |||
#{textonyms.count{|_,v| v.size > 1}} digit combinations represent Textonyms." |
|||
puts "\n25287876746242: #{textonyms["25287876746242"].join(", ")}" |
|||
</lang> |
</lang> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
There are 25104 words in unixdict.txt which can be represented by the digit key mapping. |
|||
They require 23003 digit combinations to represent them. |
|||
⚫ | |||
puts "#{Textonyms.inject(0){|n,g| g[1].length > 1 ? n+1 : n}} digit combinations correspond to a Textonym" |
|||
⚫ | |||
⚫ | |||
⚫ | |||
</pre> |
|||
<pre> |
|||
puts Textonymes["7353284667"] |
|||
rejections |
|||
selections |
|||
</pre> |
|||
<pre> |
|||
puts Textonymes["736672"] |
|||
25287876746242: claustrophobia, claustrophobic |
|||
remora |
|||
senora |
|||
</pre> |
</pre> |
||