Ordered words: Difference between revisions

Content added Content deleted
(→‎{{header|AppleScript}}: Minor modification to match change to recommended sort.)
m (→‎{{header|REXX}}: optimized the REXX program, changed comments and whitespace, used a template for the output section.)
Line 3,472: Line 3,472:
<lang rexx>/*REXX program lists (the longest) ordered word(s) from a supplied dictionary. */
<lang rexx>/*REXX program lists (the longest) ordered word(s) from a supplied dictionary. */
iFID= 'UNIXDICT.TXT' /*the filename of the word dictionary. */
iFID= 'UNIXDICT.TXT' /*the filename of the word dictionary. */
@.= /*placeholder array for list of words. */
m= 1 /*maximum length of an ordered word(s).*/
mL=0 /*maximum length of the ordered words. */
call linein iFID, 1, 0 /*point to the first word in dictionary*/
call linein iFID, 1, 0 /*point to the first word in dictionary*/
/* [↑] just in case the file is open. */
@.= /*placeholder array for list of words. */
do j=1 while lines(iFID)\==0; x=linein(iFID) /*keep reading until file is exhausted.*/
do j=1 while lines(iFID)\==0; x=linein(iFID) /*keep reading until file is exhausted.*/
w=length(x); if w<mL then iterate /*Word not long enough? Then ignore it.*/
w= length(x); if w<m then iterate /*Word not long enough? Then ignore it.*/
parse upper var x xU 1 z 2 /*get uppercase version of X & 1st char*/
if \datatype(x, 'M') then iterate /*Is it not a letter? Then ignore it. */
/* [↓] handle words of mixed case. */
parse upper var x xU 1 z 2 /*get uppercase version of X & 1st char*/
do k=2 to w; _=substr(xU, k, 1) /*process each letter in uppercase word*/
do k=2 for w-1; _= substr(xU, k, 1) /*process each letter in uppercase word*/
if \datatype(_, 'U') then iterate /*Is it not a letter? Then ignore it. */
if _<z then iterate j /*is letter < than the previous letter?*/
if _<z then iterate j /*is letter < than the previous letter?*/
z= _ /*we have a newer current letter. */
z=_ /*we have a newer current letter. */
end /*k*/ /* [↑] logic includes ≥ order. */
end /*k*/ /* [↑] logic includes ≥ order. */
mL=w /*maybe define a new maximum length. */
m= w /*maybe define a new maximum length. */
@.w=@.w x /*add the original word to a word list.*/
@.w= @.w x /*add the original word to a word list.*/
end /*j*/ /*the 1st DO needs an index for ITERATE*/
end /*j*/ /*the 1st DO needs an index for ITERATE*/
#=words(@.mL) /*just a handy─dandy variable to have. */
#= words(@.m) /*just a handy─dandy variable to have. */
say # 'word's(#) "found (of length" mL')'; say /*show the number of words and length. */
say # 'word's(#) "found (of length" m')'; say /*show the number of words and length. */
do n=1 for #; say word(@.mL, n); end /*display all the words, one to a line.*/
do n=1 for #; say word(@.m, n); end /*display all the words, one to a line.*/
exit /*stick a fork in it, we're all done. */
exit /*stick a fork in it, we're all done. */
ghijk
/*──────────────────────────────────────────────────────────────────────────────────────*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
s: if arg(1)==1 then return ''; return "s" /*a simple pluralizer (merely adds "S")*/</lang>
s: if arg(1)==1 then return ''; return "s" /*a simple pluralizer (merely adds "S")*/</lang>
'''output''' &nbsp; when using the default supplied word dictionary:
{{out|output|text=&nbsp; when using the default supplied word dictionary:}}
<pre>
<pre>
16 words found (of length 6)
16 words found (of length 6)