Find words with alternating vowels and consonants: Difference between revisions

m
→‎{{header|REXX}}: added/changed comments, changed whitespace.
(Added Forth solution)
m (→‎{{header|REXX}}: added/changed comments, changed whitespace.)
Line 1,900:
if iFID=='' | iFID=="," then iFID='unixdict.txt' /* " " " " " " */
 
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 /*save: original case and the semaphore*/
end /*#*/ /* [↑] semaphore name is uppercased. */
#= # - 1 /*adjust the record count (DO loop). */
say copies('─', 30) # "words in the dictionary file: " iFID; say
say
finds= 0 /*count of the words found (so far). */
vow= 'AEIOUaeiou'; con= 'BCDFGHJKLMNPQRSTVWXYZ' /*the list of vowels. ; list of consonants. */
con@@@=; 'BCDFGHJKLMNPQRSTVWXYZ' upper vow con /* " " " consonants. /*@@@: list of words found (so far). */
@@@= /* " " " words found (so far). */
w= 0 /*the maximum length of any word found.*/
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. */
y= $.j; upper y /*obtain a word; and also uppercase it. */
ovec= 1; ocev= 1 /*initializefor now, set both test cases as: passed.*/
@@@= /* " /*only " " words found scan (soodd far).indexed letters in word*/
do ov=1 by 2 to L; z= substr(y, evov, 1) /*examine the odd letters in the word. */
if verify(z, vow)>0 then ocevovec= 0 /*EvenOdd letter not a vowel? Then flunk. */
end /*k*/
do ev=2 by 2 to L /*only scan eve indexed letters in word*/
do ev=2 by 2 to L; z= substr(y, ocev, 1) /*examine the odd letters in the word. */
if verify(z, con)>0 then ovec= 0 /*Even letter not a consonant? Flunk. */
end /*k*/
do oc=1 by 2 to L /*only scan odd indexed letters in word*/
do oc=1 by 2 to L; z= substr(y, ecoc, 1) /*examine the odd letters in the word. */
if verify(z, con)>0 then ocev= 0 /*Odd letter not a consonant? Flunk. */
end /*k*/
do ec=2 by 2 to L /*only scan eve indexed letters in word*/
do ec=2 by 2 to L; z= substr(y, ec, 1) /*examine the odd letters in the word. */
if verify(z, vow)>0 then ocev= 0 /*Even letter not a vowel? Then flunk.*/
end /*jk*/
 
if ovec==0 & do ovocev==10 bythen 2iterate to L /*Did the word pass any test? No, /*only scan odd indexed letters in wordskip*/
finds= finds + 1 z= substr(y, ov, 1) /*examinebump the oddcount lettersof in"odd thewords" wordfound. */
w= max(w, L) if verify(z, vow)>0 then ovec= 0 /*Odd letter not a vowel? Then flunk. /*obtain the maximum length word found.*/
@@@= @@@ $.j end /*kadd a word to the list of words found*/
end /*j*/
 
do ev=2 by 2 to L /*only scan eve indexed letters in word*/
z= substr(y, ev, 1) /*examine the odd letters in the word. */
if verify(z, con)>0 then ovec= 0 /*Even letter not a consonant? Flunk. */
end /*k*/
 
do oc=1 by 2 to L /*only scan odd indexed letters in word*/
z= substr(y, oc, 1) /*examine the odd letters in the word. */
if verify(z, con)>0 then ocev= 0 /*Odd letter not a consonant? Flunk. */
end /*k*/
 
do ec=2 by 2 to L /*only scan eve indexed letters in word*/
z= substr(y, ec, 1) /*examine the odd letters in the word. */
if verify(z, vow)>0 then ocev= 0 /*Even letter not a vowel? Then flunk.*/
end /*k*/
 
if ovec==0 & ocev==0 then iterate /*Did the word pass any test? No, skip*/
finds= finds + 1 /*bump the count of "odd words" found. */
w= max(w, L) /*obtain the maximum length word found.*/
@@@= @@@ $.j /*add a word to the list of words found*/
end /*j*/
/*stick a fork in it, we're all done. */
say copies('─', 30) finds ' words found with a minimum length of ' minL
_=
do out=1 for finds; z= word(@@@, out) /*build a list that will be displayed. */
if length(_ right(z, w))>130 then do; say substr(_, 2); _=; end /*show a line.*/
_= _ right(z, w) /*append (aligned word) to output line.*/