Anonymous user
Teacup rim text: Difference between revisions
→{{header|REXX}}: added the REXX computer programming language for this task.
(Added Go) |
(→{{header|REXX}}: added the REXX computer programming language for this task.) |
||
Line 884:
{{Out}}
<pre>['aaa', 'apt', 'arc', 'ate', 'car', 'eat', 'iii', 'pta', 'rca', 'tap', 'tea']</pre>
=={{header|REXX}}==
The words used from from a local copy of <big>''unixdict.txt''</big> as
used elsewhere on <big><tt>Rosetta Code</tt></big>.
All words that contained non─letter (Latin) characters (periods, decimal digits, minus signs,
underbars, or embedded blanks) weren't considered as candidates for circular words.
Also, all words were uppercased to make them caseless.
The dictionary wasn't assumed to be sorted in any way.
<lang rexx>/*REXX program finds circular words (length three or more) using a dictionary. */
parse arg iFID L . /*obtain optional arguments from the CL*/
if iFID==''|iFID=="," then iFID= 'UNIXDICT.TXT' /*Not specified? Then use the default.*/
if L==''| L=="," then L= 3 /* " " " " " " */
#= 0 /*number of words in dictionary, Len>L.*/
@.= /*a caseless non─duplicated word array.*/
do r=0 while lines(iFID)\==0 /*read all lines (words) in dictionary.*/
u= linein(iFID); upper u /*get a word from dictionary; uppercase*/
if length(u)<L | @.u\=='' then iterate /*length must be L or more, no dups.*/
if \datatype(u, 'U') then iterate /*Word contains non-letters? Then skip*/
@.u = u /*assign a word from the dictionary. */
#= # + 1 /*bump the word count that meets specs.*/
$.#= u /*assign legitimate word to the $ array*/
end /*r*/ /* [↑] dictionary need not be sorted. */
say "There're " r ' entries in the dictionary (of all types): ' iFID
say "There're " # ' words in the dictionary of at least length ' L
say
cw= 0 /*the number of circular words (so far)*/
do j=1 for #; x= $.j /*obtain the Jth word in the list. */
y= x /*use a copy of X for circulating. */
do k=1 for length(x)-1 /*"circulate" the litters in the word. */
y= substr(y, 2)left(y, 1) /*add the first letter to the word end.*/
if @.y=='' then iterate j /*if not a word, then skip this word. */
end /*k*/
cw= cw + 1 /*bump counter of circular words found.*/
say 'circular word: ' x /*display a circular word to the term. */
end /*j*/
say
say cw ' circular words were found.' /*stick a fork in it, we're all done. */</lang>
{{out|output|text= when using the default inputs:}}
<pre>
There're 25104 entries in the dictionary (of all types): UNIXDICT.TXT
There're 24819 words in the dictionary of at least length 3
circular word: AAA
circular word: APT
circular word: ARC
circular word: ATE
circular word: CAR
circular word: EAT
circular word: III
circular word: PTA
circular word: RCA
circular word: TAP
circular word: TEA
11 circular words were found.
</pre>
=={{header|zkl}}==
|