Ordered words: Difference between revisions

m
→‎{{header|REXX}}: optimized the REXX program, changed comments and whitespace, used a template for the output section.
(→‎{{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:
<lang rexx>/*REXX program lists (the longest) ordered word(s) from a supplied dictionary. */
iFID= 'UNIXDICT.TXT' /*the filename of the word dictionary. */
@.m= 1 /*placeholdermaximum arraylength forof listan ofordered wordsword(s). */
mL=0 /*maximum length of the ordered words. */
call linein iFID, 1, 0 /*point to the first word in dictionary*/
@.= /*placeholder [↑] just in casearray thefor filelist isof openwords. */
do j=1 while lines(iFID)\==0; x=linein(iFID) /*keep reading until file is exhausted.*/
w= length(x); if w<mLm then iterate /*Word not long enough? Then ignore it.*/
parse upper var if \datatype(x, 'M') xU 1 z 2 then iterate /*Is it not a letter? Then ignore /*get uppercase version of X & 1stit. char*/
parse upper var x xU 1 z 2 /*get [↓]uppercase handle wordsversion of mixed case. X & 1st char*/
do k=2 tofor w-1; _= substr(xU, k, 1) /*process each letter in uppercase word*/
if \datatype(_, 'U')<z then iterate j /*Is it not a /*is letter? < Thenthan ignorethe it.previous letter?*/
ifz= _<z then iterate j /*iswe have a newer current letter. < than the previous letter?*/
z=_ /*we have a newer current letter. */
end /*k*/ /* [↑] logic includes ≥ order. */
mL m=w w /*maybe define a new maximum length. */
@.w= @.w x /*add the original word to a word list.*/
end /*j*/ /*the 1st DO needs an index for ITERATE*/
#= words(@.mLm) /*just a handy─dandy variable to have. */
say # 'word's(#) "found (of length" mLm')'; say /*show the number of words and length. */
do n=1 for #; say word(@.mLm, n); end /*display all the words, one to a line.*/
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>
'''{{out|output''' |text=&nbsp; when using the default supplied word dictionary:}}
<pre>
16 words found (of length 6)