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"
NUMS = "22233344455566677778889999"*2
dict = "unixdict.txt"
textonyms = File.open("unixdict.txt"){|f| f.map(&:chomp).group_by {|word| word.tr(CHARS, NUMS) } }
puts "There are
#{textonyms.count{|_,v| v.size > 1}} digit combinations represent Textonyms."
puts "\n25287876746242: #{textonyms["25287876746242"].join(", ")}"
</lang>
{{out}}
<pre>
▲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
25287876746242: claustrophobia, claustrophobic
</pre>
|