Textonyms: Difference between revisions
m
syntax highlighting fixup automation
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
|||
Line 47:
{{trans|Python}}
<
L(chars) ‘abc def ghi jkl mno pqrs tuv wxyz’.split(‘ ’)
V num = L.index + 2
Line 94:
print(‘ #. maps to: #.’.format(num, wrds.join(‘, ’)))
interactiveconversions()</
{{out}}
Line 123:
=={{header|ALGOL 68}}==
{{works with|ALGOL 68G|Any - tested with release 2.8.3.win32}} Uses the Algol 68G specific "to upper" procedure.
<
# use the associative array in the Associate array/iteration task #
PR read "aArray.a68" PR
Line 259:
FI
</syntaxhighlight>
{{out}}
<pre>
Line 275:
=={{header|C}}==
{{libheader|GLib}}
<
#include <stdio.h>
#include <stdlib.h>
Line 449:
}
return EXIT_SUCCESS;
}</
{{out}}
Line 473:
=={{header|C++}}==
<
#include <iostream>
#include <unordered_map>
Line 590:
tc.match("27484247");
tc.match("7244967473642");
}</
{{out}}
<pre>Read 25104 words from unixdict.txt
Line 611:
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.
<syntaxhighlight lang="clojure">
(def table
{\a 2 \b 2 \c 2 \A 2 \B 2 \C 2
Line 636:
(count mapping) " digit combinations to represent them. "
(count textonyms) " digit combinations represent Textonyms.")))
</syntaxhighlight>
{{out}}
<pre>
Line 644:
=={{header|D}}==
{{trans|Raku}}
<
import std.stdio, std.string, std.range, std.algorithm, std.ascii;
Line 670:
foreach (p; textonyms.schwartzSort!(p => -p[0].length).take(5))
writefln(" %s => %-(%s %)", p[]);
}</
{{out}}
<pre>There are 24978 words in unixdict.txt which can be represented by the digit key mapping.
Line 695:
{{libheader| System.Character}}
{{Trans|C++}}
<syntaxhighlight lang="delphi">
program Textonyms;
Line 896:
end.
</syntaxhighlight>
{{out}}
Line 916:
=={{header|Factor}}==
{{works with|Factor|0.99 2020-07-03}}
<
io.files kernel literals math math.parser prettyprint sequences
unicode ;
Line 942:
${} digit combinations represent Textonyms.I] nl nl
"7325 -> " write words textonyms 7325 of .</
{{out}}
<pre>
Line 957:
Like the [[Textonyms#Python|Phython example]],
the examples shown are the numbers that map to the most words.
<
import (
Line 1,097:
fmt.Fprintln(w, "\t", k, "maps to:", strings.Join(v, ", "))
}
}</
{{out}}
<pre>
Line 1,119:
=={{header|Haskell}}==
<
import Data.Function (on)
import Data.List (groupBy, sortBy)
Line 1,189:
++ fmap
showTextonym
(take 5 $ sortBy (flip compare `on` (length . fst . head)) textonymList)</
{{out}}
<pre style="font-size:80%">There are 24978 words in unixdict.txt which can be represented by the digit key mapping.
Line 1,212:
Or, in terms of ''Data.Map'' and ''traverse'':
<
import Data.List (groupBy, maximum, sortBy, sortOn)
import qualified Data.Map as M
Line 1,301:
]
where
rjust n c = (drop . length) <*> (replicate n c <>)</
{{Out}}
<pre>There are 24978 words in unixdict.txt which can be represented
Line 1,325:
=={{header|Io}}==
<
setupLetterToDigitMapping
Line 1,428:
)
main</
{{output}}
<pre>There are 24978 words in unixdict.txt which can be represented by the digit key mapping.
Line 1,465:
=={{header|J}}==
<
strip=:dyad define
Line 1,502:
reps=. {&digits@(letters&i.)&.> valid NB. reps is digit seq
reporttext report (#valid);y;(#~.reps);+/(1<#)/.~reps
)</
Required example:
<
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.
661 digit combinations represent Textonyms.</
In this example, the intermediate results in textonymrpt would look like this (just looking at the first 5 elements of the really big values:
<
22233344455566677778889999
letters
Line 1,524:
┌─┬──┬───┬───┬──┐
│2│22│222│226│22│
└─┴──┴───┴───┴──┘</
Here's another example:
<
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.
1473 digit combinations represent Textonyms.</
=={{header|Java}}==
{{trans|c++}}
<
import java.io.IOException;
import java.nio.charset.StandardCharsets;
Line 1,698:
}
}
</syntaxhighlight>
{{out|Output with "java RTextonyms ./unixdict.txt"}}
<pre>
Line 1,718:
=={{header|jq}}==
The following requires a version of jq with "gsub".
<
gsub("a|b|c|A|B|C"; "2")
| gsub("d|e|f|D|E|F"; "3")
Line 1,757:
;
explore</
{{out}}
<
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.
Line 1,767:
The longest Textonyms in the word list have length 11:
26456746242 maps to: ["Anglophobia","Anglophobic"]
24636272673 maps to: ["CinemaScope","Cinemascope"]</
=={{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".
'''Function'''
<
const tcode = (Regex=>Char)[r"A|B|C|Ä|Å|Á|Â|Ç" => '2',
Line 1,796:
return tnym
end
</syntaxhighlight>
'''Main'''
<syntaxhighlight lang="julia">
dname = "/usr/share/dict/american-english"
DF = open(dname, "r")
Line 1,839:
println(@sprintf "%7s (%2d) %s" k length(v) join(v, ", "))
end
</syntaxhighlight>
{{out}}
Line 1,885:
=={{header|Kotlin}}==
<
import java.io.File
Line 1,947:
fun main(args: Array<String>) {
processList()
}</
{{out}}
Line 1,981:
=={{header|Lua}}==
<
http = require("socket.http")
keys = {"VOICEMAIL", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"}
Line 2,035:
-- Main procedure
showReport(textonyms(http.request(dictFile)))</
{{out}}
<pre>There are 24983 words in http://www.puzzlers.org/pub/wordlists/unixdict.txt
Line 2,043:
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<
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
Line 2,058:
KeyValueMap[List,TakeLargestBy[grouped,Length,1]]//Grid
Print["5 longest words with textonyms:"]
List@@@Normal[ReverseSortBy[grouped,First/*Length][[;;5]]]//Grid</
{{out}}
<pre>Number of words from Textonyms/wordlist are: 71125
Line 2,073:
=={{header|MiniScript}}==
This solution assumes the Mini Micro environment (providing the listUtil and mapUtil modules, as well as the englishWords.txt file).
<
import "mapUtil"
Line 2,121:
print num + " -> " + numToWords.get(num)
end if
end while</
{{out}}
<pre>There are 64664 words in englishWords.txt which can be represented
Line 2,137:
=={{header|Nim}}==
{{trans|Kotlin}}
<
const
Line 2,183:
echo &"""{l[0].len:4} {l[0]:>14} {l[1].join(", ")}"""
processList(WordList)</
{{out}}
Line 2,215:
=={{header|Perl}}==
<
# filter word-file for valid input, transform to low-case
Line 2,231:
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.
@{[scalar @textonyms]} digit combinations represent Textonyms.";</
{{out}}
<pre>There are 24978 words in 'unixdict.txt' which can be represented by the digit key mapping.
Line 2,238:
=={{header|Phix}}==
<!--<
<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>
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: #008080;">end</span> <span style="color: #008080;">for</span>
<!--</
{{Out}}
<small>(my unixdict.txt seems to have grown by 4 entries sometime in the past couple of years...)</small>
Line 2,329:
=={{header|PowerShell}}==
<syntaxhighlight lang="powershell">
$url = "http://www.puzzlers.org/pub/wordlists/unixdict.txt"
$file = "$env:TEMP\unixdict.txt"
Line 2,375:
Remove-Item -Path $file -Force -ErrorAction SilentlyContinue
</syntaxhighlight>
{{Out}}
<pre>
Line 2,405:
=={{header|Python}}==
<
import urllib.request
Line 2,466:
print(" %s maps to: %s" % (num, ', '.join(wrds)))
interactiveconversions()</
{{out}}
Line 2,500:
<code>unixdict.txt</code> has words like <q>2nd</q> which would not be valid using letters only, but is textable.
<
(module+ test (require tests/eli-tester))
(module+ test
Line 2,580:
(module+ main
(report-on-file "data/unixdict.txt"))</
{{out}}
Line 2,614:
=={{header|Raku}}==
(formerly Perl 6)
<syntaxhighlight lang="raku"
my @words = slurp($src).lines.grep(/ ^ <alpha>+ $ /);
Line 2,635:
say "\nTop 5 in length:";
say " ",$_ for @textonyms.sort(-*.key.chars)[^5];</
{{out}}
<pre>There are 24978 words in unixdict.txt which can be represented by the digit key mapping.
Line 2,658:
Extra code was added detect and display a count illegal words (words not representable by the ''key digits''), and
<br>also duplicate words in the dictionary.
<
parse arg iFID . /*obtain optional fileID from the C.L. */
if iFID=='' | iFID=="," then iFID='UNIXDICT.TXT' /*Not specified? Then use the default.*/
Line 2,713:
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 #*/
s: if arg(1)==1 then return ''; return "s" /*a simple pluralizer.*/</
{{out|output|text= when using the default input file:}}
Line 2,746:
=={{header|Ruby}}==
<
CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
NUMS = "22233344455566677778889999" * 2
Line 2,758:
puts "\n25287876746242: #{textonyms["25287876746242"].join(", ")}"
</syntaxhighlight>
{{out}}
<pre>
Line 2,769:
=={{header|Rust}}==
<
use std::fs::File;
use std::io::{self, BufRead};
Line 2,858:
Err(error) => eprintln!("{}: {}", args[1], error),
}
}</
{{out}}
Line 2,883:
=={{header|Sidef}}==
{{trans|Raku}}
<
var dials = words.group_by {
Line 2,902:
say "\nTop 5 in length:";
say textonyms.sort_by { |k,_| -k.len }.first(5).join("\n");</
{{out}}
<pre>
Line 2,926:
=={{header|Swift}}==
<
func textCharacter(_ ch: Character) -> Character? {
Line 3,017:
} catch {
print(error.localizedDescription)
}</
{{out}}
Line 3,042:
=={{header|Tcl}}==
<
2 -> ABC
3 -> DEF
Line 3,109:
}
puts [main $keymap $url]</
{{out}}
Line 3,123:
=={{header|VBScript}}==
<
Set objInFile = objFSO.OpenTextFile(objFSO.GetParentFolderName(WScript.ScriptFullName) &_
"\unixdict.txt",1)
Line 3,169:
objMoreThanOneWord.Count & " digit combinations represent Textonyms."
objInFile.Close</
{{out}}
<pre>There are 24978 words in "unixdict.txt" which can be represented by the digit key mapping.
Line 3,180:
{{libheader|Wren-sort}}
{{libheader|Wren-fmt}}
<
import "/str" for Char, Str
import "/sort" for Sort
Line 3,229:
System.print("Length Textonym Words")
System.print("====== ============== =====")
for (l in longest.take(6)) Fmt.print(f, l.key.count, l.key, l.value)</
{{out}}
Line 3,265:
{{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.
<
var ZC=Import("zklCurl");
var keypad=Dictionary(
Line 3,294:
foreach k,v in (wcnt.filter('wrap([(k,v)]){ v.len()==maxWordPerNum })){
println(" %s is the textonym of: %s".fmt(k,v.concat(", ")));
}</
{{out}}
<pre>
|