Jump to content

Find words with alternating vowels and consonants: Difference between revisions

Added Algol 68
(Add Factor)
(Added Algol 68)
Line 8:
 
 
 
=={{header|ALGOL 68}}==
<lang algol68># read the list of words and show words with alternating vowels and #
# consonants #
IF FILE input file;
STRING file name = "unixdict.txt";
open( input file, file name, stand in channel ) /= 0
THEN
# failed to open the file #
print( ( "Unable to open """ + file name + """", newline ) )
ELSE
# file opened OK #
BOOL at eof := FALSE;
# set the EOF handler for the file #
on logical file end( input file, ( REF FILE f )BOOL:
BEGIN
# note that we reached EOF on the #
# latest read #
at eof := TRUE;
# return TRUE so processing can continue #
TRUE
END
);
# returns the length of the string w #
OP LENGTH = ( STRING w )INT: ( UPB w - LWB w ) + 1;
# returns TRUE if c is a vowel, FALSE otherwise #
OP ISVOWEL = ( CHAR c )BOOL: ( c = "a" OR c = "e" OR c = "i" OR c = "o" OR c = "u" );
# blank pads s on the left to width characters #
PRIO PAD = 1;
OP PAD = ( INT width, STRING s )STRING:
IF LENGTH s >= width THEN s
ELSE
STRING result := s;
WHILE LENGTH result < width DO " " +=: result OD;
result
FI; # PAD #
INT alternating count := 0;
WHILE STRING word;
get( input file, ( word, newline ) );
NOT at eof
DO
IF LENGTH word >= 10
THEN
# the word is at least 10 characters #
BOOL is alternating := TRUE;
BOOL have vowel := ISVOWEL word[ LWB word ];
FOR w pos FROM LWB word + 1 TO UPB word
WHILE BOOL had vowel = have vowel;
have vowel := ISVOWEL word[ w pos ];
is alternating := have vowel = NOT had vowel
DO SKIP OD;
IF is alternating THEN
# the characters of word alternate between vowels and #
# non-vowels #
alternating count +:= 1;
print( ( " ", 15 PAD word ) );
IF LENGTH word > 15 OR alternating count MOD 6 = 0 THEN
print( ( newline ) )
FI
FI
FI
OD;
close( input file );
print( ( newline, whole( alternating count, 0 ), " words of alternating vowels and consonants found", newline ) )
FI</lang>
{{out}}
<pre>
aboriginal apologetic bimolecular borosilicate calorimeter capacitate
capacitive capitoline capitulate caricature colatitude coloratura
colorimeter debilitate decelerate decolonize definitive degenerate
deliberate demodulate denominate denotative deregulate desiderata
desideratum dilapidate diminutive epigenetic facilitate hemosiderin
heretofore hexadecimal homogenate inoperative judicature latitudinal
legitimate lepidolite literature locomotive manipulate metabolite
nicotinamide oratorical paragonite pejorative peridotite peripatetic
polarimeter recitative recuperate rehabilitate rejuvenate remunerate
repetitive reticulate savonarola similitude solicitude tananarive
telekinesis teratogenic topologize unilateral unimodular uninominal
verisimilitude
67 words of alternating vowels and consonants found
</pre>
 
=={{header|Factor}}==
3,068

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.