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 |
<lang rexx>/*REXX program finds all the caseless alternade words (within an identified dictionary).*/ |
||
parse arg |
parse arg minL iFID . /*obtain optional arguments from the CL*/ |
||
if |
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 |
do #=1 while lines(iFID)\==0 /*read each word in the file (word=X).*/ |
||
x= strip( linein( iFID) ) |
x= strip( linein( iFID) ) /*pick off a word from the input line. */ |
||
$.#= x; |
$.#= x; upper x; @.x= . /*save: original case and the semaphore*/ |
||
end /*#*/ |
end /*#*/ /* [↑] semaphore name is uppercased. */ |
||
#= # - 1 /*adjust word count because of DO loop.*/ |
#= # - 1 /*adjust word count because of DO loop.*/ |
||
finds= 0 /*count of the alternade words found. */ |
|||
say copies('─', 30) # "words in the dictionary file: " iFID |
|||
say |
|||
chrsU= chrs; upper chrsU /*obtain an uppercase version of chrs.*/ |
|||
do j=1 for #; L= length($.j) /*process all the words that were found*/ |
|||
if L<minL then iterate /*Is word too short? Then ignore it. */ |
|||
p.= /*initialize 2 parts of alternade word.*/ |
|||
do k=1 for L; _= k // 2 /*build the " " " " " */ |
|||
p._= p._ || substr($.j, k, 1) /*append to one part of alternade word.*/ |
|||
end /*k*/ |
|||
if _<p then iterate j /*Less than the previous? Then skip it*/ |
|||
⚫ | |||
end /*k*/ |
|||
parse upper value p.0 p.1 with p0 p1 /*obtain the uppercase alternade parts.*/ |
|||
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*/ |
||
⚫ | |||
say copies('─', |
say copies('─',30) finds ' alternade words found with a minimum length of ' minL</lang> |
||
{{out|output|text= when using the default input:}} |
{{out|output|text= when using the default input:}} |
||
<pre> |
<pre> |