Textonyms: Difference between revisions
Content deleted Content added
→{{header|Python}}: Refactored. |
J |
||
Line 33: | Line 33: | ||
Use a word list and keypad mapping other than English. |
Use a word list and keypad mapping other than English. |
||
=={{header|J}}== |
|||
<lang J>require'regex strings web/gethttp' |
|||
strip=:dyad define |
|||
(('(?s)',x);'') rxrplc y |
|||
) |
|||
fetch=:monad define |
|||
txt=. '.*<pre>' strip '</pre>.*' strip gethttp y |
|||
cutopen tolower txt-.' ' |
|||
) |
|||
keys=:noun define |
|||
2 abc |
|||
3 def |
|||
4 ghi |
|||
5 jkl |
|||
6 mno |
|||
7 pqrs |
|||
8 tuv |
|||
9 wxyz |
|||
) |
|||
reporttext=:noun define |
|||
There are #{0} words in #{1} which can be represnted by the Textonyms mapping. |
|||
They require #{2} digit combinations to represent them. |
|||
#{3} digit combinations represent Textonyms. |
|||
) |
|||
report=:dyad define |
|||
x rplc (":&.>y),.~('#{',":,'}'"_)&.>i.#y |
|||
) |
|||
textonymrpt=:dyad define |
|||
'digits letters'=. |:>;,&.>,&.>/&.>/"1 <;._1;._2 x |
|||
valid=. (#~ */@e.&letters&>) fetch y NB. ignore illegals |
|||
reps=. {&digits@(letters&i.)&.> valid NB. reps is digit seq |
|||
reporttext report (#valid);y;(#~.reps);+/(1<#)/.~reps |
|||
)</lang> |
|||
Required example: |
|||
<lang J> keys textonymrpt 'http://rosettacode.org/wiki/Textonyms/wordlist' |
|||
There are 13085 words in http://rosettacode.org/wiki/Textonyms/wordlist which can be represnted by the Textonyms mapping. |
|||
They require 11932 digit combinations to represent them. |
|||
661 digit combinations represent Textonyms.</lang> |
|||
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 |
|||
22233344455566677778889999 |
|||
letters |
|||
abcdefghijklmnopqrstuvwxyz |
|||
5{.valid |
|||
┌─┬──┬───┬───┬──┐ |
|||
│a│aa│aaa│aam│ab│ |
|||
└─┴──┴───┴───┴──┘ |
|||
5{.reps |
|||
┌─┬──┬───┬───┬──┐ |
|||
│2│22│222│226│22│ |
|||
└─┴──┴───┴───┴──┘</lang> |
|||
=={{header|Perl}}== |
=={{header|Perl}}== |