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]

}
puts "There are #{File.readlines(dict).size} words in #{dict} which can be represented by the digit key mapping.
end
They require #{textonyms.size} digit combinations to represent them.
#{textonyms.count{|_,v| v.size > 1}} digit combinations represent Textonyms."

puts "\n25287876746242: #{textonyms["25287876746242"].join(", ")}"
</lang>
</lang>
{{out}}
{{out}}
<pre>
<pre>
puts "There are #{Textonyms.inject(0){|n,g| n+g[1].length}} words in #{"Wordlist"} which can be represnted by the Textonyms mapping."
There are 25104 words in unixdict.txt which can be represented by the digit key mapping.
puts "They require #{Textonyms.length} digit combinations to represent them."
They require 23003 digit combinations to represent them.
1485 digit combinations represent Textonyms.
puts "#{Textonyms.inject(0){|n,g| g[1].length > 1 ? n+1 : n}} digit combinations correspond to a Textonym"

There are 132916 words in Wordlist which can be represnted by the Textonyms mapping.
They require 117868 digit combinations to represent them.
9579 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>