Textonyms: Difference between revisions

→‎{{header|Ruby}}: use tr and group_by
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:
=={{header|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 132916#{File.readlines(dict).size} words in Wordlist#{dict} which can be represntedrepresented by the Textonymsdigit key mapping.
end
They require 117868#{textonyms.size} digit combinations to represent them.
#{textonyms.count{|_,v| v.size > 1}} digit combinations represent Textonyms."
 
puts "\n25287876746242: #{textonyms["25287876746242"].join(", ")}"
</lang>
{{out}}
<pre>
puts "There are #{Textonyms.inject(0){|n,g| n+g[1].length}}25104 words in #{"Wordlist"}unixdict.txt which can be represntedrepresented by the Textonymsdigit key mapping."
puts "They require #{Textonyms.length}23003 digit combinations to represent them."
95791485 digit combinations correspondrepresent to a TextonymTextonyms.
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>
 
1,149

edits