Textonyms: Difference between revisions

Content added Content deleted
(→‎{{header|Ruby}}: use tr and group_by)
Line 2,748: Line 2,748:
<lang ruby>
<lang ruby>
CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
NUMS = "22233344455566677778889999"*2
NUMS = "22233344455566677778889999" * 2
dict = "unixdict.txt"
dict = "unixdict.txt"


textonyms = File.open("unixdict.txt"){|f| f.map(&:chomp).group_by {|word| word.tr(CHARS, NUMS) } }
textonyms = File.open(dict){|f| f.map(&:chomp).group_by {|word| word.tr(CHARS, NUMS) } }


puts "There are #{File.readlines(dict).size} words in #{dict} which can be represented by the digit key mapping.
puts "There are #{File.readlines(dict).size} words in #{dict} which can be represented by the digit key mapping.