Jump to content

ABC words: Difference between revisions

m
→‎{{header|REXX}}: added a comment.
m (→‎{{header|REXX}}: used more idiomatic code.)
m (→‎{{header|REXX}}: added a comment.)
Line 655:
 
It also allows the   (ABC)   characters to be specified on the command line (CL) as well as the dictionary file identifier.
<lang rexx>/*REXX pgmprogram finds "ABC"all the caseless alternade words (within an identified dict.dictionary) where ABC are found in order.*/
parse arg chrsminL iFID . /*obtain optional arguments from the CL*/
if chrsminL=='' | chrsminL=="," then chrsminL= 'abc'6 /*Not specified? Then use the default.*/
if iFID=='' | iFID=="," then iFID='unixdict.txt' /* " " " " " " */
@.= /*default value of any dictionary word.*/
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; upper x; @.#x= x . /*save: original case. and the semaphore*/
end /*#*/ /* [↑] semaphore name is uppercased. */
#= # - 1 /*adjust word count because of DO loop.*/
sayfinds= copies('─',0 30) # "words in the dictionary file: " iFID /*count of the alternade words found. */
Lsay = lengthcopies(chrs'─', 30) # "words in the dictionary file: " /*obtain the length of the ABC chars.*/iFID
say
chrsU= chrs; upper chrsU /*obtain an uppercase version of chrs.*/
finds= 0 do j=1 for #; L= length($.j) /*countprocess ofall the words "ABC"that wordswere found. */
doif j=1L<minL forthen #iterate /*Is word too short? Then ignore it. /*process all the words that were found*/
ifp.= verify(chrsU, @.j)>0 then iterate /*All charactersinitialize found?2 parts No,of thenalternade skipword.*/
p= 0 do k=1 for L; _= k // 2 /*build the " " " /*initialize the position location." " */
do kp._=1 for L p._ || substr($.j, k, 1) /*examineappend eachto letterone ofpart theof ABCalternade chartsword.*/
end _= pos( substr(chrsU, k, 1), @.j) /*find the position of the Kth letter.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 parse upper value p.0 p.1 with p0 p1 /*bumpobtain the countuppercase ofalternade "ABC" words foundparts. */
sayif right(left($@.j, 30), 40) p0=='' | @.p1=='' then iterate /*indenteither originalparts wordof foralternade readability.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*/
p= _ /*savestick thea positionfork ofin theit, last letterwe're all done. */
 
say copies('─', 30) finds ' ' "ABC"alternade words found usingwith thea characters:minimum 'length of ' chrsminL</lang>
{{out|output|text=&nbsp; when using the default input:}}
<pre>
Cookies help us deliver our services. By using our services, you agree to our use of cookies.