Jump to content

Textonyms: Difference between revisions

1,896 bytes added ,  9 years ago
+ D entry
(+ D entry)
Line 174:
Key '7244967473642' matches: schizophrenia schizophrenic
</pre>
 
=={{header|D}}==
{{trans|Perl6}}
<lang d>void main() {
import std.stdio, std.string, std.range, std.algorithm, std.ascii;
 
immutable src = "unixdict.txt";
const words = src.File.byLineCopy.map!strip.filter!(w => w.all!isAlpha).array;
 
immutable table = makeTrans("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",
"2223334445556667777888999922233344455566677778889999");
 
string[][string] dials;
foreach (const word; words)
dials[word.translate(table)] ~= word;
 
auto textonyms = dials.byPair.filter!(p => p[1].length > 1).array;
 
writefln("There are %d words in %s which can be represented by the digit key mapping.", words.length, src);
writefln("They require %d digit combinations to represent them.", dials.length);
writefln("%d digit combinations represent Textonyms.", textonyms.length);
 
"\nTop 5 in ambiguity:".writeln;
foreach (p; textonyms.schwartzSort!(p => -p[1].length).take(5))
writefln(" %s => %-(%s %)", p[]);
 
"\nTop 5 in length:".writeln;
foreach (p; textonyms.schwartzSort!(p => -p[0].length).take(5))
writefln(" %s => %-(%s %)", p[]);
}</lang>
{{out}}
<pre>There are 24978 words in unixdict.txt which can be represented by the digit key mapping.
They require 22903 digit combinations to represent them.
1473 digit combinations represent Textonyms.
 
Top 5 in ambiguity:
729 => paw pax pay paz raw ray saw sax say
269 => amy any bmw bow box boy cow cox coy
2273 => acre bard bare base cape card care case
726 => pam pan ram ran sam san sao scm
426 => gam gao ham han ian ibm ibn
 
Top 5 in length:
25287876746242 => claustrophobia claustrophobic
7244967473642 => schizophrenia schizophrenic
666628676342 => onomatopoeia onomatopoeic
49376746242 => hydrophobia hydrophobic
6388537663 => mettlesome nettlesome</pre>
 
=={{header|Go}}==
Uses a local file and shows its name rather than re-fetching a URL each run and printing that URL.
Cookies help us deliver our services. By using our services, you agree to our use of cookies.