ABC words: Difference between revisions

Content added Content deleted
m (→‎{{header|REXX}}: used more idiomatic code.)
m (→‎{{header|REXX}}: added a comment.)
Line 655: Line 655:


It also allows the   (ABC)   characters to be specified on the command line (CL) as well as the dictionary file identifier.
It also allows the   (ABC)   characters to be specified on the command line (CL) as well as the dictionary file identifier.
<lang rexx>/*REXX pgm finds "ABC" words (within an identified dict.) where ABC are found in order.*/
<lang rexx>/*REXX program finds all the caseless alternade words (within an identified dictionary).*/
parse arg chrs iFID . /*obtain optional arguments from the CL*/
parse arg minL iFID . /*obtain optional arguments from the CL*/
if chrs=='' | chrs=="," then chrs= 'abc' /*Not specified? Then use the default.*/
if minL=='' | minL=="," then minL= 6 /*Not specified? Then use the default.*/
if iFID=='' | iFID=="," then iFID='unixdict.txt' /* " " " " " " */
if iFID=='' | iFID=="," then iFID='unixdict.txt' /* " " " " " " */
@.= /*default value of any dictionary word.*/
@.= /*default value of any dictionary word.*/
do #=1 while lines(iFID)\==0 /*read each word in the file (word=X).*/
do #=1 while lines(iFID)\==0 /*read each word in the file (word=X).*/
x= strip( linein( iFID) ) /*pick off a word from the input line. */
x= strip( linein( iFID) ) /*pick off a word from the input line. */
$.#= x; upper x; @.#= x /*save: original case. */
$.#= x; upper x; @.x= . /*save: original case and the semaphore*/
end /*#*/ /* [↑] semaphore name is uppercased. */
end /*#*/ /* [↑] semaphore name is uppercased. */
#= # - 1 /*adjust word count because of DO loop.*/
#= # - 1 /*adjust word count because of DO loop.*/
say copies('─', 30) # "words in the dictionary file: " iFID
finds= 0 /*count of the alternade words found. */
L = length(chrs) /*obtain the length of the ABC chars.*/
say copies('─', 30) # "words in the dictionary file: " iFID
say
chrsU= chrs; upper chrsU /*obtain an uppercase version of chrs.*/
finds= 0 /*count of the "ABC" words found. */
do j=1 for #; L= length($.j) /*process all the words that were found*/
do j=1 for # /*process all the words that were found*/
if L<minL then iterate /*Is word too short? Then ignore it. */
if verify(chrsU, @.j)>0 then iterate /*All characters found? No, then skip.*/
p.= /*initialize 2 parts of alternade word.*/
p= 0 /*initialize the position location. */
do k=1 for L; _= k // 2 /*build the " " " " " */
do k=1 for L /*examine each letter of the ABC charts*/
p._= p._ || substr($.j, k, 1) /*append to one part of alternade word.*/
_= pos( substr(chrsU, k, 1), @.j) /*find the position of the Kth letter.*/
end /*k*/
if _<p then iterate j /*Less than the previous? Then skip it*/
p= _ /*save the position of the last letter.*/
end /*k*/


finds= finds + 1 /*bump the count of "ABC" words found. */
parse upper value p.0 p.1 with p0 p1 /*obtain the uppercase alternade parts.*/
say right(left($.j, 30), 40) /*indent original word for readability.*/
if @.p0=='' | @.p1=='' then iterate /*either parts of alternade not extant?*/
finds= finds + 1 /*bump the count of alternades found.*/
say right(left($.j, 20), 25) left(p.1, 10) left(p.0, 10) /*indent a bit.*/
end /*j*/
end /*j*/
/*stick a fork in it, we're all done. */

say copies('─', 30) finds ' "ABC" words found using the characters: ' chrs</lang>
say copies('─',30) finds ' alternade words found with a minimum length of ' minL</lang>
{{out|output|text=&nbsp; when using the default input:}}
{{out|output|text=&nbsp; when using the default input:}}
<pre>
<pre>