Textonyms: Difference between revisions

892 bytes added ,  8 years ago
m
→‎{{header|REXX}}: added/changed comments and whitespace, changed indentations, split some output lines into two, used better phrasing.
m (added whitespace before the TOC, added a ;Task and ;Extra credit (bold) headers.)
m (→‎{{header|REXX}}: added/changed comments and whitespace, changed indentations, split some output lines into two, used better phrasing.)
Line 1,314:
This REXX version checks for and displays the count of the number of (illegal) words not representable by the ''key digits''.
<br>It also detects and displays the count of duplicate words.
<lang rexx>/*REXX program counts and displays the number of textonyms that are in a file (dictionary) file*/
parse arg iFID . /*getobtain optional fileID offrom the fileC.L. */
if iFID=='' then iFID='UNIXDICT.TXT' /*filenameNot ofspecified? the wordThen use the dictionarydefault.*/
@.=0 /*the placeholder of digit combinations placeholder.*/
!.=; $.= /*sparse array of textonyms; words. */
alphabet= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' /*the supported alphabet to be used. */
digitKey= 22233344455566677778889999 /*translated alphabet to digdigit keykeys. */
digKey=0; wordCount=0 /*#number digit combinations; wordCount.*/
ills=0; dups=0; longest=0; mostus=0 /*illegals; duplicateduplicated words; litlongest..*/
first=0; last=0; long=0; most=0 /*for: first, last, longest, ···most counts. */
call linein iFID, 1, 0 /*point to the first char in dictdictionary*/
#=0 /*number of textonyms in the file (so far).*/
 
/* [↑] ───in case file is open.*/
do j=1 while lines(iFID)\==0 /*keep reading untilthe exhausted.file until exhausted*/
x=linein(iFID); y=x; upper x /*get a word; save anda copy; uppercase it. */
if \datatype(x,'U') then do; ills=ills+1; iterate; end /*is it illegal? */
if $.x\=='' then do; dups=dups+1; iterate; end /*is it duplicate?*/
else $.x=. /*indicate that it's a righteous word. */
wordCount=wordCount+1 /*bump the word count (for the file). */
z=translate(x, digitKey, alphabet) /*build a translated digit key word. */
@.z=@.z+1 /*flag that the digit key word exists. */
!.z=!.z y; _=words(!.z) /*build a list of sameequivalent digit key.(s)*/
if _>most then do; mostus=z; most=_; end /*remember the "mostus" digKeys digit keys. */
if @.z==2 then do; #=#+1 /*bump the count of the textonyms. */
if first==0 then first=z /*the first textonym found. */
last=z /* " last " " */
_=length(!.z) /*the length (# chars) of the digit key.*/
if _>longest then long=z /*is this the longest textonym ? */
longest=max(_, longest) /*now, shoot foruse this len.length as a target/goal*/
end /* [↑] discretionary stuff (extra credit). */
if @.z\==1 then iterate /*Does it already exist? Then Skip it.*/
digKey=digKey+1 /*bump the count of digit key words. */
end /*j*/
@@whichCan...=' 'which can be represented by the digit key mapping.'
@Ta = 'There are /* [↑] ───in case file is open.*/'
say wordCount 'is the number of words in file "'iFID'"' @@
say 'The dictionary file being used is: ' iFID
if ills\==0 then say ills 'word's(ills) "contained illegal characters."
say @Ta wordCount ' words in the file' @whichCan...
if dups\==0 then say dups "duplicate word"s(dups) 'detected.'
if ills\==0 then say @Ta ills ' word's(ills) "contained illegal characters."
say 'They require' digKey "combination"s(digKey) 'to represent them.'
if dups\==0 then say @Ta dups " duplicate word"s(dups) 'in the dictionary detected.'
say # 'digit combination's(#) "represent Textonyms."
say 'TheyThe textonyms require ' digKey " combination"s(digKey) 'to represent them.'
say @Ta # ' digit combination's(#) " that can represent Textonyms."
say
if first\==0 then say ' first digit key=' !.first
if last\==0 then say ' last digit key=' !.last
if long\==0 then say ' longest digit key=' !.long
if most\==0 then say ' numerous digit key=' !.mostus ' ('most "words)"
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
/*──────────────────────────────────S subroutine────────────────────────*/
s: if arg(1)==1 then return ''; return '"s'" /*a simple pluralizer.*/</lang>
'''output''' &nbsp; when using the default input file:
<pre>
The dictionary file being used is: UNIXDICT.TXT
24978There isare the number24978 of words in the file "UNIXDICT.TXT" which can be represented by the digit key mapping.
There are 126 words contained illegal characters.
They require 22903 combinations to represent them.
1473The textonyms require 22903 digit combinations to represent Textonymsthem.
There are 1473 digit combinations that can represent Textonyms.
 
first digit key= aaa aba abc cab
Line 1,375 ⟶ 1,378:
'''output''' &nbsp; when using the input file: &nbsp; <tt> textonyms.txt </tt>
<pre>
The dictionary file being used is: textonyms.txt
12990There isare the number12990 of words in the file "textonyms.txt" which can be represented by the digit key mapping.
There are 95 duplicate words werein the dictionary detected.
They require 11932 combinations to represent them.
650The textonyms require 11932 digit combinations to represent Textonymsthem.
TheyThere requireare 22903 650 digit combinations to that can represent themTextonyms.
 
first digit key= AA AB AC BA BB BC CA CB