Find words with alternating vowels and consonants: Difference between revisions
Content added Content deleted
(Added Forth solution) |
m (→{{header|REXX}}: added/changed comments, changed whitespace.) |
||
Line 1,900: | Line 1,900: | ||
if iFID=='' | iFID=="," then iFID='unixdict.txt' /* " " " " " " */ |
if iFID=='' | iFID=="," then iFID='unixdict.txt' /* " " " " " " */ |
||
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; upper x |
$.#= x; upper x /*save: original case and the semaphore*/ |
||
end /*#*/ |
end /*#*/ /* [↑] semaphore name is uppercased. */ |
||
#= # - 1 /*adjust the record count (DO loop). */ |
#= # - 1 /*adjust the record count (DO loop). */ |
||
say copies('─', 30) # "words in the dictionary file: " iFID |
say copies('─', 30) # "words in the dictionary file: " iFID; say |
||
say |
|||
finds= 0 /*count of the words found (so far). */ |
finds= 0 /*count of the words found (so far). */ |
||
vow= ' |
vow= 'aeiou'; con= 'BCDFGHJKLMNPQRSTVWXYZ' /*list of vowels; list of consonants. */ |
||
@@@=; upper vow con /*@@@: list of words found (so far). */ |
|||
⚫ | |||
w= 0 /*the maximum length of any word found.*/ |
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 /*for now, set both test cases: passed.*/ |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
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.*/ |
|||
⚫ | |||
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*/ |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
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*/ |
|||
⚫ | |||
/*stick a fork in it, we're all done. */ |
/*stick a fork in it, we're all done. */ |
||
say copies('─', 30) finds ' words found with a minimum length of ' minL |
say copies('─', 30) finds ' words found with a minimum length of ' minL |
||
_= |
_= |
||
do out=1 for finds; z= word(@@@, out) |
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.*/ |
if length(_ right(z, w))>130 then do; say substr(_, 2); _=; end /*show a line.*/ |
||
_= _ right(z, w) /*append (aligned word) to output line.*/ |
_= _ right(z, w) /*append (aligned word) to output line.*/ |