Textonyms
var words = ARGF.grep(/^[[:alpha:]]+\z/)
var dials = words.group_by {
.tr('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
'2223334445556667777888999922233344455566677778889999')
}
var textonyms = dials.grep_v { .len > 1 }
say <<-"END"
There are #{words.len} words which can be represented by the digit key mapping.
They require #{dials.len} digit combinations to represent them.
#{textonyms.len} digit combinations represent Textonyms.
END
say "Top 5 in ambiguity:"
say textonyms.sort_by { |_,v| -v.len }.first(5).join("\n")
say "\nTop 5 in length:"
say textonyms.sort_by { |k,_| -k.len }.first(5).join("\n")Output:
Last updated
Was this helpful?