Textonyms: Difference between revisions

Content added Content deleted
m (syntax highlighting fixup automation)
Line 47: Line 47:
{{trans|Python}}
{{trans|Python}}


<lang 11l>[Char = String] CH2NUM
<syntaxhighlight lang="11l">[Char = String] CH2NUM
L(chars) ‘abc def ghi jkl mno pqrs tuv wxyz’.split(‘ ’)
L(chars) ‘abc def ghi jkl mno pqrs tuv wxyz’.split(‘ ’)
V num = L.index + 2
V num = L.index + 2
Line 94: Line 94:
print(‘ #. maps to: #.’.format(num, wrds.join(‘, ’)))
print(‘ #. maps to: #.’.format(num, wrds.join(‘, ’)))


interactiveconversions()</lang>
interactiveconversions()</syntaxhighlight>


{{out}}
{{out}}
Line 123: Line 123:
=={{header|ALGOL 68}}==
=={{header|ALGOL 68}}==
{{works with|ALGOL 68G|Any - tested with release 2.8.3.win32}} Uses the Algol 68G specific "to upper" procedure.
{{works with|ALGOL 68G|Any - tested with release 2.8.3.win32}} Uses the Algol 68G specific "to upper" procedure.
<lang algol68># find textonyms in a list of words #
<syntaxhighlight lang="algol68"># find textonyms in a list of words #
# use the associative array in the Associate array/iteration task #
# use the associative array in the Associate array/iteration task #
PR read "aArray.a68" PR
PR read "aArray.a68" PR
Line 259: Line 259:


FI
FI
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 275: Line 275:
=={{header|C}}==
=={{header|C}}==
{{libheader|GLib}}
{{libheader|GLib}}
<lang c>#include <stdbool.h>
<syntaxhighlight lang="c">#include <stdbool.h>
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
Line 449: Line 449:
}
}
return EXIT_SUCCESS;
return EXIT_SUCCESS;
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 473: Line 473:


=={{header|C++}}==
=={{header|C++}}==
<lang cpp>#include <fstream>
<syntaxhighlight lang="cpp">#include <fstream>
#include <iostream>
#include <iostream>
#include <unordered_map>
#include <unordered_map>
Line 590: Line 590:
tc.match("27484247");
tc.match("27484247");
tc.match("7244967473642");
tc.match("7244967473642");
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>Read 25104 words from unixdict.txt
<pre>Read 25104 words from unixdict.txt
Line 611: Line 611:
The [[Textonyms#Tcl|Tcl example]] counts all the words which share a digit sequence with another word. Like the other
The [[Textonyms#Tcl|Tcl example]] counts all the words which share a digit sequence with another word. Like the other
examples, this considers a textonym to be a digit sequence which maps to more than one word.
examples, this considers a textonym to be a digit sequence which maps to more than one word.
<syntaxhighlight lang="clojure">
<lang Clojure>
(def table
(def table
{\a 2 \b 2 \c 2 \A 2 \B 2 \C 2
{\a 2 \b 2 \c 2 \A 2 \B 2 \C 2
Line 636: Line 636:
(count mapping) " digit combinations to represent them. "
(count mapping) " digit combinations to represent them. "
(count textonyms) " digit combinations represent Textonyms.")))
(count textonyms) " digit combinations represent Textonyms.")))
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 644: Line 644:
=={{header|D}}==
=={{header|D}}==
{{trans|Raku}}
{{trans|Raku}}
<lang d>void main() {
<syntaxhighlight lang="d">void main() {
import std.stdio, std.string, std.range, std.algorithm, std.ascii;
import std.stdio, std.string, std.range, std.algorithm, std.ascii;


Line 670: Line 670:
foreach (p; textonyms.schwartzSort!(p => -p[0].length).take(5))
foreach (p; textonyms.schwartzSort!(p => -p[0].length).take(5))
writefln(" %s => %-(%s %)", p[]);
writefln(" %s => %-(%s %)", p[]);
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>There are 24978 words in unixdict.txt which can be represented by the digit key mapping.
<pre>There are 24978 words in unixdict.txt which can be represented by the digit key mapping.
Line 695: Line 695:
{{libheader| System.Character}}
{{libheader| System.Character}}
{{Trans|C++}}
{{Trans|C++}}
<syntaxhighlight lang="delphi">
<lang Delphi>
program Textonyms;
program Textonyms;


Line 896: Line 896:
end.
end.


</syntaxhighlight>
</lang>


{{out}}
{{out}}
Line 916: Line 916:
=={{header|Factor}}==
=={{header|Factor}}==
{{works with|Factor|0.99 2020-07-03}}
{{works with|Factor|0.99 2020-07-03}}
<lang factor>USING: assocs assocs.extras interpolate io io.encodings.utf8
<syntaxhighlight lang="factor">USING: assocs assocs.extras interpolate io io.encodings.utf8
io.files kernel literals math math.parser prettyprint sequences
io.files kernel literals math math.parser prettyprint sequences
unicode ;
unicode ;
Line 942: Line 942:
${} digit combinations represent Textonyms.I] nl nl
${} digit combinations represent Textonyms.I] nl nl


"7325 -> " write words textonyms 7325 of .</lang>
"7325 -> " write words textonyms 7325 of .</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 957: Line 957:
Like the [[Textonyms#Python|Phython example]],
Like the [[Textonyms#Python|Phython example]],
the examples shown are the numbers that map to the most words.
the examples shown are the numbers that map to the most words.
<lang go>package main
<syntaxhighlight lang="go">package main


import (
import (
Line 1,097: Line 1,097:
fmt.Fprintln(w, "\t", k, "maps to:", strings.Join(v, ", "))
fmt.Fprintln(w, "\t", k, "maps to:", strings.Join(v, ", "))
}
}
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 1,119: Line 1,119:


=={{header|Haskell}}==
=={{header|Haskell}}==
<lang haskell>import Data.Char (toUpper)
<syntaxhighlight lang="haskell">import Data.Char (toUpper)
import Data.Function (on)
import Data.Function (on)
import Data.List (groupBy, sortBy)
import Data.List (groupBy, sortBy)
Line 1,189: Line 1,189:
++ fmap
++ fmap
showTextonym
showTextonym
(take 5 $ sortBy (flip compare `on` (length . fst . head)) textonymList)</lang>
(take 5 $ sortBy (flip compare `on` (length . fst . head)) textonymList)</syntaxhighlight>
{{out}}
{{out}}
<pre style="font-size:80%">There are 24978 words in unixdict.txt which can be represented by the digit key mapping.
<pre style="font-size:80%">There are 24978 words in unixdict.txt which can be represented by the digit key mapping.
Line 1,212: Line 1,212:
Or, in terms of ''Data.Map'' and ''traverse'':
Or, in terms of ''Data.Map'' and ''traverse'':


<lang haskell>import Data.Function (on)
<syntaxhighlight lang="haskell">import Data.Function (on)
import Data.List (groupBy, maximum, sortBy, sortOn)
import Data.List (groupBy, maximum, sortBy, sortOn)
import qualified Data.Map as M
import qualified Data.Map as M
Line 1,301: Line 1,301:
]
]
where
where
rjust n c = (drop . length) <*> (replicate n c <>)</lang>
rjust n c = (drop . length) <*> (replicate n c <>)</syntaxhighlight>
{{Out}}
{{Out}}
<pre>There are 24978 words in unixdict.txt which can be represented
<pre>There are 24978 words in unixdict.txt which can be represented
Line 1,325: Line 1,325:
=={{header|Io}}==
=={{header|Io}}==


<lang Io>main := method(
<syntaxhighlight lang="io">main := method(
setupLetterToDigitMapping
setupLetterToDigitMapping


Line 1,428: Line 1,428:
)
)


main</lang>
main</syntaxhighlight>
{{output}}
{{output}}
<pre>There are 24978 words in unixdict.txt which can be represented by the digit key mapping.
<pre>There are 24978 words in unixdict.txt which can be represented by the digit key mapping.
Line 1,465: Line 1,465:
=={{header|J}}==
=={{header|J}}==


<lang J>require'regex strings web/gethttp'
<syntaxhighlight lang="j">require'regex strings web/gethttp'


strip=:dyad define
strip=:dyad define
Line 1,502: Line 1,502:
reps=. {&digits@(letters&i.)&.> valid NB. reps is digit seq
reps=. {&digits@(letters&i.)&.> valid NB. reps is digit seq
reporttext report (#valid);y;(#~.reps);+/(1<#)/.~reps
reporttext report (#valid);y;(#~.reps);+/(1<#)/.~reps
)</lang>
)</syntaxhighlight>


Required example:
Required example:


<lang J> keys textonymrpt 'http://rosettacode.org/wiki/Textonyms/wordlist'
<syntaxhighlight lang="j"> keys textonymrpt 'http://rosettacode.org/wiki/Textonyms/wordlist'
There are 13085 words in http://rosettacode.org/wiki/Textonyms/wordlist which can be represented by the digit key mapping.
There are 13085 words in http://rosettacode.org/wiki/Textonyms/wordlist which can be represented by the digit key mapping.
They require 11932 digit combinations to represent them.
They require 11932 digit combinations to represent them.
661 digit combinations represent Textonyms.</lang>
661 digit combinations represent Textonyms.</syntaxhighlight>


In this example, the intermediate results in textonymrpt would look like this (just looking at the first 5 elements of the really big values:
In this example, the intermediate results in textonymrpt would look like this (just looking at the first 5 elements of the really big values:


<lang J> digits
<syntaxhighlight lang="j"> digits
22233344455566677778889999
22233344455566677778889999
letters
letters
Line 1,524: Line 1,524:
┌─┬──┬───┬───┬──┐
┌─┬──┬───┬───┬──┐
│2│22│222│226│22│
│2│22│222│226│22│
└─┴──┴───┴───┴──┘</lang>
└─┴──┴───┴───┴──┘</syntaxhighlight>


Here's another example:
Here's another example:


<lang J> keys textonymrpt 'http://www.puzzlers.org/pub/wordlists/unixdict.txt'
<syntaxhighlight lang="j"> keys textonymrpt 'http://www.puzzlers.org/pub/wordlists/unixdict.txt'
There are 24978 words in http://www.puzzlers.org/pub/wordlists/unixdict.txt which can be represnted by the digit key mapping.
There are 24978 words in http://www.puzzlers.org/pub/wordlists/unixdict.txt which can be represnted by the digit key mapping.
They require 22903 digit combinations to represent them.
They require 22903 digit combinations to represent them.
1473 digit combinations represent Textonyms.</lang>
1473 digit combinations represent Textonyms.</syntaxhighlight>


=={{header|Java}}==
=={{header|Java}}==
{{trans|c++}}
{{trans|c++}}
<lang java>
<syntaxhighlight lang="java">
import java.io.IOException;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.charset.StandardCharsets;
Line 1,698: Line 1,698:
}
}
}
}
</syntaxhighlight>
</lang>
{{out|Output with "java RTextonyms ./unixdict.txt"}}
{{out|Output with "java RTextonyms ./unixdict.txt"}}
<pre>
<pre>
Line 1,718: Line 1,718:
=={{header|jq}}==
=={{header|jq}}==
The following requires a version of jq with "gsub".
The following requires a version of jq with "gsub".
<lang jq>def textonym_value:
<syntaxhighlight lang="jq">def textonym_value:
gsub("a|b|c|A|B|C"; "2")
gsub("a|b|c|A|B|C"; "2")
| gsub("d|e|f|D|E|F"; "3")
| gsub("d|e|f|D|E|F"; "3")
Line 1,757: Line 1,757:
;
;


explore</lang>
explore</syntaxhighlight>
{{out}}
{{out}}
<lang sh>$ jq -R -r -c -s -f textonyms.jq textonyms.txt
<syntaxhighlight lang="sh">$ jq -R -r -c -s -f textonyms.jq textonyms.txt
There are 13085 words in the Textonyms/wordlist word list that can be represented by the digit-key mapping.
There are 13085 words in the Textonyms/wordlist word list that can be represented by the digit-key mapping.
They require 11932 digit combinations to represent them.
They require 11932 digit combinations to represent them.
Line 1,767: Line 1,767:
The longest Textonyms in the word list have length 11:
The longest Textonyms in the word list have length 11:
26456746242 maps to: ["Anglophobia","Anglophobic"]
26456746242 maps to: ["Anglophobia","Anglophobic"]
24636272673 maps to: ["CinemaScope","Cinemascope"]</lang>
24636272673 maps to: ["CinemaScope","Cinemascope"]</syntaxhighlight>


=={{header|Julia}}==
=={{header|Julia}}==
This solution uses an <tt>aspell</tt> dictionary on the local machine as its word source. The character to number mapping is done via regular expressions and Julia's <tt>replace</tt> function. Because this list contains accented characters, the matching expressions were expanded to include such characters. Words are case sensitive, but the mapping is not, so for example both "Homer" and "homer" are included in the tabulation, each coded as "46637".
This solution uses an <tt>aspell</tt> dictionary on the local machine as its word source. The character to number mapping is done via regular expressions and Julia's <tt>replace</tt> function. Because this list contains accented characters, the matching expressions were expanded to include such characters. Words are case sensitive, but the mapping is not, so for example both "Homer" and "homer" are included in the tabulation, each coded as "46637".
'''Function'''
'''Function'''
<lang Julia>using Printf
<syntaxhighlight lang="julia">using Printf


const tcode = (Regex=>Char)[r"A|B|C|Ä|Å|Á|Â|Ç" => '2',
const tcode = (Regex=>Char)[r"A|B|C|Ä|Å|Á|Â|Ç" => '2',
Line 1,796: Line 1,796:
return tnym
return tnym
end
end
</syntaxhighlight>
</lang>


'''Main'''
'''Main'''
<syntaxhighlight lang="julia">
<lang Julia>
dname = "/usr/share/dict/american-english"
dname = "/usr/share/dict/american-english"
DF = open(dname, "r")
DF = open(dname, "r")
Line 1,839: Line 1,839:
println(@sprintf "%7s (%2d) %s" k length(v) join(v, ", "))
println(@sprintf "%7s (%2d) %s" k length(v) join(v, ", "))
end
end
</syntaxhighlight>
</lang>


{{out}}
{{out}}
Line 1,885: Line 1,885:


=={{header|Kotlin}}==
=={{header|Kotlin}}==
<lang scala>// version 1.1.4-3
<syntaxhighlight lang="scala">// version 1.1.4-3


import java.io.File
import java.io.File
Line 1,947: Line 1,947:
fun main(args: Array<String>) {
fun main(args: Array<String>) {
processList()
processList()
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 1,981: Line 1,981:


=={{header|Lua}}==
=={{header|Lua}}==
<lang Lua>-- Global variables
<syntaxhighlight lang="lua">-- Global variables
http = require("socket.http")
http = require("socket.http")
keys = {"VOICEMAIL", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"}
keys = {"VOICEMAIL", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"}
Line 2,035: Line 2,035:


-- Main procedure
-- Main procedure
showReport(textonyms(http.request(dictFile)))</lang>
showReport(textonyms(http.request(dictFile)))</syntaxhighlight>
{{out}}
{{out}}
<pre>There are 24983 words in http://www.puzzlers.org/pub/wordlists/unixdict.txt
<pre>There are 24983 words in http://www.puzzlers.org/pub/wordlists/unixdict.txt
Line 2,043: Line 2,043:


=={{header|Mathematica}}/{{header|Wolfram Language}}==
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<lang Mathematica>ClearAll[Numerify,rls]
<syntaxhighlight lang="mathematica">ClearAll[Numerify,rls]
rls={"A"->2,"B"->2,"C"->2,"D"->3,"E"->3,"F"->3,"G"->4,"H"->4,"I"->4,"J"->5,"K"->5,"L"->5,"M"->6,"N"->6,"O"->6,"P"->7,"Q"->7,"R"->7,"S"->7,"T"->8,"U"->8,"V"->8,"W"->9,"X"->9,"Y"->9,"Z"->9};
rls={"A"->2,"B"->2,"C"->2,"D"->3,"E"->3,"F"->3,"G"->4,"H"->4,"I"->4,"J"->5,"K"->5,"L"->5,"M"->6,"N"->6,"O"->6,"P"->7,"Q"->7,"R"->7,"S"->7,"T"->8,"U"->8,"V"->8,"W"->9,"X"->9,"Y"->9,"Z"->9};
Numerify[s_String]:=Characters[ToUpperCase[s]]/.rls
Numerify[s_String]:=Characters[ToUpperCase[s]]/.rls
Line 2,058: Line 2,058:
KeyValueMap[List,TakeLargestBy[grouped,Length,1]]//Grid
KeyValueMap[List,TakeLargestBy[grouped,Length,1]]//Grid
Print["5 longest words with textonyms:"]
Print["5 longest words with textonyms:"]
List@@@Normal[ReverseSortBy[grouped,First/*Length][[;;5]]]//Grid</lang>
List@@@Normal[ReverseSortBy[grouped,First/*Length][[;;5]]]//Grid</syntaxhighlight>
{{out}}
{{out}}
<pre>Number of words from Textonyms/wordlist are: 71125
<pre>Number of words from Textonyms/wordlist are: 71125
Line 2,073: Line 2,073:
=={{header|MiniScript}}==
=={{header|MiniScript}}==
This solution assumes the Mini Micro environment (providing the listUtil and mapUtil modules, as well as the englishWords.txt file).
This solution assumes the Mini Micro environment (providing the listUtil and mapUtil modules, as well as the englishWords.txt file).
<lang MiniScript>import "listUtil"
<syntaxhighlight lang="miniscript">import "listUtil"
import "mapUtil"
import "mapUtil"


Line 2,121: Line 2,121:
print num + " -> " + numToWords.get(num)
print num + " -> " + numToWords.get(num)
end if
end if
end while</lang>
end while</syntaxhighlight>
{{out}}
{{out}}
<pre>There are 64664 words in englishWords.txt which can be represented
<pre>There are 64664 words in englishWords.txt which can be represented
Line 2,137: Line 2,137:
=={{header|Nim}}==
=={{header|Nim}}==
{{trans|Kotlin}}
{{trans|Kotlin}}
<lang Nim>import algorithm, sequtils, strformat, strutils, tables
<syntaxhighlight lang="nim">import algorithm, sequtils, strformat, strutils, tables


const
const
Line 2,183: Line 2,183:
echo &"""{l[0].len:4} {l[0]:>14} {l[1].join(", ")}"""
echo &"""{l[0].len:4} {l[0]:>14} {l[1].join(", ")}"""


processList(WordList)</lang>
processList(WordList)</syntaxhighlight>


{{out}}
{{out}}
Line 2,215: Line 2,215:


=={{header|Perl}}==
=={{header|Perl}}==
<lang perl>my $src = 'unixdict.txt';
<syntaxhighlight lang="perl">my $src = 'unixdict.txt';


# filter word-file for valid input, transform to low-case
# filter word-file for valid input, transform to low-case
Line 2,231: Line 2,231:
print "There are @{[scalar @words]} words in '$src' which can be represented by the digit key mapping.
print "There are @{[scalar @words]} words in '$src' which can be represented by the digit key mapping.
They require @{[scalar @dials]} digit combinations to represent them.
They require @{[scalar @dials]} digit combinations to represent them.
@{[scalar @textonyms]} digit combinations represent Textonyms.";</lang>
@{[scalar @textonyms]} digit combinations represent Textonyms.";</syntaxhighlight>
{{out}}
{{out}}
<pre>There are 24978 words in 'unixdict.txt' which can be represented by the digit key mapping.
<pre>There are 24978 words in 'unixdict.txt' which can be represented by the digit key mapping.
Line 2,238: Line 2,238:


=={{header|Phix}}==
=={{header|Phix}}==
<!--<lang Phix>(phixonline)-->
<!--<syntaxhighlight lang="phix">(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #004080;">sequence</span> <span style="color: #000000;">digit</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">repeat</span><span style="color: #0000FF;">(-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">255</span><span style="color: #0000FF;">)</span>
<span style="color: #004080;">sequence</span> <span style="color: #000000;">digit</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">repeat</span><span style="color: #0000FF;">(-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">255</span><span style="color: #0000FF;">)</span>
Line 2,313: Line 2,313:
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">" %s encodes %s\n"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">words</span><span style="color: #0000FF;">[</span><span style="color: #000000;">long_idx</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">]])</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">" %s encodes %s\n"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">words</span><span style="color: #0000FF;">[</span><span style="color: #000000;">long_idx</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">]])</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<!--</lang>-->
<!--</syntaxhighlight>-->
{{Out}}
{{Out}}
<small>(my unixdict.txt seems to have grown by 4 entries sometime in the past couple of years...)</small>
<small>(my unixdict.txt seems to have grown by 4 entries sometime in the past couple of years...)</small>
Line 2,329: Line 2,329:


=={{header|PowerShell}}==
=={{header|PowerShell}}==
<syntaxhighlight lang="powershell">
<lang PowerShell>
$url = "http://www.puzzlers.org/pub/wordlists/unixdict.txt"
$url = "http://www.puzzlers.org/pub/wordlists/unixdict.txt"
$file = "$env:TEMP\unixdict.txt"
$file = "$env:TEMP\unixdict.txt"
Line 2,375: Line 2,375:


Remove-Item -Path $file -Force -ErrorAction SilentlyContinue
Remove-Item -Path $file -Force -ErrorAction SilentlyContinue
</syntaxhighlight>
</lang>
{{Out}}
{{Out}}
<pre>
<pre>
Line 2,405: Line 2,405:


=={{header|Python}}==
=={{header|Python}}==
<lang python>from collections import defaultdict
<syntaxhighlight lang="python">from collections import defaultdict
import urllib.request
import urllib.request


Line 2,466: Line 2,466:
print(" %s maps to: %s" % (num, ', '.join(wrds)))
print(" %s maps to: %s" % (num, ', '.join(wrds)))


interactiveconversions()</lang>
interactiveconversions()</syntaxhighlight>


{{out}}
{{out}}
Line 2,500: Line 2,500:
<code>unixdict.txt</code> has words like <q>2nd</q> which would not be valid using letters only, but is textable.
<code>unixdict.txt</code> has words like <q>2nd</q> which would not be valid using letters only, but is textable.


<lang racket>#lang racket
<syntaxhighlight lang="racket">#lang racket
(module+ test (require tests/eli-tester))
(module+ test (require tests/eli-tester))
(module+ test
(module+ test
Line 2,580: Line 2,580:


(module+ main
(module+ main
(report-on-file "data/unixdict.txt"))</lang>
(report-on-file "data/unixdict.txt"))</syntaxhighlight>


{{out}}
{{out}}
Line 2,614: Line 2,614:
=={{header|Raku}}==
=={{header|Raku}}==
(formerly Perl 6)
(formerly Perl 6)
<lang perl6>my $src = 'unixdict.txt';
<syntaxhighlight lang="raku" line>my $src = 'unixdict.txt';


my @words = slurp($src).lines.grep(/ ^ <alpha>+ $ /);
my @words = slurp($src).lines.grep(/ ^ <alpha>+ $ /);
Line 2,635: Line 2,635:


say "\nTop 5 in length:";
say "\nTop 5 in length:";
say " ",$_ for @textonyms.sort(-*.key.chars)[^5];</lang>
say " ",$_ for @textonyms.sort(-*.key.chars)[^5];</syntaxhighlight>
{{out}}
{{out}}
<pre>There are 24978 words in unixdict.txt which can be represented by the digit key mapping.
<pre>There are 24978 words in unixdict.txt which can be represented by the digit key mapping.
Line 2,658: Line 2,658:
Extra code was added detect and display a count illegal words &nbsp; (words not representable by the ''key digits''), &nbsp; and
Extra code was added detect and display a count illegal words &nbsp; (words not representable by the ''key digits''), &nbsp; and
<br>also duplicate words in the dictionary.
<br>also duplicate words in the dictionary.
<lang rexx>/*REXX program counts and displays the number of textonyms that are in a dictionary file*/
<syntaxhighlight lang="rexx">/*REXX program counts and displays the number of textonyms that are in a dictionary file*/
parse arg iFID . /*obtain optional fileID from the C.L. */
parse arg iFID . /*obtain optional fileID from the C.L. */
if iFID=='' | iFID=="," then iFID='UNIXDICT.TXT' /*Not specified? Then use the default.*/
if iFID=='' | iFID=="," then iFID='UNIXDICT.TXT' /*Not specified? Then use the default.*/
Line 2,713: Line 2,713:
commas: parse arg _; do jc=length(_)-3 to 1 by -3; _=insert(',', _, jc); end; return _
commas: parse arg _; do jc=length(_)-3 to 1 by -3; _=insert(',', _, jc); end; return _
tell: arg ##; say 'There are ' right(commas(##), L)' ' arg(2).; return /*commatize #*/
tell: arg ##; say 'There are ' right(commas(##), L)' ' arg(2).; return /*commatize #*/
s: if arg(1)==1 then return ''; return "s" /*a simple pluralizer.*/</lang>
s: if arg(1)==1 then return ''; return "s" /*a simple pluralizer.*/</syntaxhighlight>


{{out|output|text=&nbsp; when using the default input file:}}
{{out|output|text=&nbsp; when using the default input file:}}
Line 2,746: Line 2,746:


=={{header|Ruby}}==
=={{header|Ruby}}==
<lang ruby>
<syntaxhighlight lang="ruby">
CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
NUMS = "22233344455566677778889999" * 2
NUMS = "22233344455566677778889999" * 2
Line 2,758: Line 2,758:


puts "\n25287876746242: #{textonyms["25287876746242"].join(", ")}"
puts "\n25287876746242: #{textonyms["25287876746242"].join(", ")}"
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 2,769: Line 2,769:


=={{header|Rust}}==
=={{header|Rust}}==
<lang rust>use std::collections::HashMap;
<syntaxhighlight lang="rust">use std::collections::HashMap;
use std::fs::File;
use std::fs::File;
use std::io::{self, BufRead};
use std::io::{self, BufRead};
Line 2,858: Line 2,858:
Err(error) => eprintln!("{}: {}", args[1], error),
Err(error) => eprintln!("{}: {}", args[1], error),
}
}
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 2,883: Line 2,883:
=={{header|Sidef}}==
=={{header|Sidef}}==
{{trans|Raku}}
{{trans|Raku}}
<lang ruby>var words = ARGF.grep(/^[[:alpha:]]+\z/);
<syntaxhighlight lang="ruby">var words = ARGF.grep(/^[[:alpha:]]+\z/);


var dials = words.group_by {
var dials = words.group_by {
Line 2,902: Line 2,902:


say "\nTop 5 in length:";
say "\nTop 5 in length:";
say textonyms.sort_by { |k,_| -k.len }.first(5).join("\n");</lang>
say textonyms.sort_by { |k,_| -k.len }.first(5).join("\n");</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 2,926: Line 2,926:


=={{header|Swift}}==
=={{header|Swift}}==
<lang swift>import Foundation
<syntaxhighlight lang="swift">import Foundation


func textCharacter(_ ch: Character) -> Character? {
func textCharacter(_ ch: Character) -> Character? {
Line 3,017: Line 3,017:
} catch {
} catch {
print(error.localizedDescription)
print(error.localizedDescription)
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 3,042: Line 3,042:
=={{header|Tcl}}==
=={{header|Tcl}}==


<lang Tcl>set keymap {
<syntaxhighlight lang="tcl">set keymap {
2 -> ABC
2 -> ABC
3 -> DEF
3 -> DEF
Line 3,109: Line 3,109:
}
}


puts [main $keymap $url]</lang>
puts [main $keymap $url]</syntaxhighlight>


{{out}}
{{out}}
Line 3,123: Line 3,123:


=={{header|VBScript}}==
=={{header|VBScript}}==
<lang vb>Set objFSO = CreateObject("Scripting.FileSystemObject")
<syntaxhighlight lang="vb">Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objInFile = objFSO.OpenTextFile(objFSO.GetParentFolderName(WScript.ScriptFullName) &_
Set objInFile = objFSO.OpenTextFile(objFSO.GetParentFolderName(WScript.ScriptFullName) &_
"\unixdict.txt",1)
"\unixdict.txt",1)
Line 3,169: Line 3,169:
objMoreThanOneWord.Count & " digit combinations represent Textonyms."
objMoreThanOneWord.Count & " digit combinations represent Textonyms."


objInFile.Close</lang>
objInFile.Close</syntaxhighlight>
{{out}}
{{out}}
<pre>There are 24978 words in "unixdict.txt" which can be represented by the digit key mapping.
<pre>There are 24978 words in "unixdict.txt" which can be represented by the digit key mapping.
Line 3,180: Line 3,180:
{{libheader|Wren-sort}}
{{libheader|Wren-sort}}
{{libheader|Wren-fmt}}
{{libheader|Wren-fmt}}
<lang ecmascript>import "io" for File
<syntaxhighlight lang="ecmascript">import "io" for File
import "/str" for Char, Str
import "/str" for Char, Str
import "/sort" for Sort
import "/sort" for Sort
Line 3,229: Line 3,229:
System.print("Length Textonym Words")
System.print("Length Textonym Words")
System.print("====== ============== =====")
System.print("====== ============== =====")
for (l in longest.take(6)) Fmt.print(f, l.key.count, l.key, l.value)</lang>
for (l in longest.take(6)) Fmt.print(f, l.key.count, l.key, l.value)</syntaxhighlight>


{{out}}
{{out}}
Line 3,265: Line 3,265:
{{trans|Python}}
{{trans|Python}}
Like the Python example, this solution uses the Unix Dictionary, rather than the textonyms word list as I don't want to parse the HTML.
Like the Python example, this solution uses the Unix Dictionary, rather than the textonyms word list as I don't want to parse the HTML.
<lang zkl>URL:="http://www.puzzlers.org/pub/wordlists/unixdict.txt";
<syntaxhighlight lang="zkl">URL:="http://www.puzzlers.org/pub/wordlists/unixdict.txt";
var ZC=Import("zklCurl");
var ZC=Import("zklCurl");
var keypad=Dictionary(
var keypad=Dictionary(
Line 3,294: Line 3,294:
foreach k,v in (wcnt.filter('wrap([(k,v)]){ v.len()==maxWordPerNum })){
foreach k,v in (wcnt.filter('wrap([(k,v)]){ v.len()==maxWordPerNum })){
println(" %s is the textonym of: %s".fmt(k,v.concat(", ")));
println(" %s is the textonym of: %s".fmt(k,v.concat(", ")));
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>