Textonyms: Difference between revisions

jq
(→‎{{header|Perl 6}}: much faster version)
(jq)
Line 269:
They require 22903 digit combinations to represent them.
1473 digit combinations represent Textonyms.</lang>
 
=={{header|jq}}==
The following requires a version of jq with "gsub".
<lang jq>def textonym_value:
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")
| 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");
 
def explore:
def max_length: [.[] | length] | max;
split("\n")
| map(select(test("^[a-zA-Z]+$"))) # select the strictly alphabetic strings
| length as $nwords
| reduce .[] as $line
( {};
($line | textonym_value) as $key
| .[$key] += [$line] )
| max_length as $max_length
| "There are \($nwords) in the Textonyms/wordlist word list that can be represented by the digit-key mapping.",
"They require \(length) digit combinations to represent them.",
"\( [.[] | select(length>1) ] | length ) digit combinations represent Textonyms.",
"The numbers mapping to the most words map to \($max_length) words in the given word list:",
(to_entries[] | select((.value|length) == $max_length) | " \(.key) maps to: \(.value|tostring)")
;
 
explore</lang>
{{out}}
<lang sh>$ jq -R -r -c -s -f textonyms.jq textonyms.txt
There are 13085 in the Textonyms/wordlist word list that can be represented by the digit-key mapping.
They require 11932 digit combinations to represent them.
661 digit combinations represent Textonyms.
The numbers mapping to the most words map to 15 words in the given word list:
27 maps to: ["AP","AQ","AR","AS","Ar","As","BP","BR","BS","Br","CP","CQ","CR","Cr","Cs"]</lang>
 
=={{header|Perl}}==
2,515

edits