I'm working on modernizing Rosetta Code's infrastructure. Starting with communications. Please accept this time-limited open invite to RC's Slack.. --Michael Mol (talk) 20:59, 30 May 2020 (UTC)

Find words which odd letters are consonants and even letters are vowels or vice versa

From Rosetta Code
Find words which odd letters are consonants and even letters are vowels or vice versa is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.
Task

Using the dictionary   unixdict.txt,   find words which odd letters are consonants and even letters are vowels or vice versa.
Display the words here (on this page).

The length of any word shown should have a length   > 9.


Other tasks related to string operations:
Metrics
Counting
Remove/replace
Anagrams/Derangements/shuffling
Find/Search/Determine
Formatting
Song lyrics/poems/Mad Libs/phrases
Tokenize
Sequences



ALGOL 68[edit]

# 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 ( " " * ( width - LENGTH s ) ) + s FI;
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
Output:
      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

AWK[edit]

( length( $1 ) >= 10 ) \
{
# have an appropriate length word
word = $1;
haveVowel = word ~ /^[aeiou]/;
isAlternating = 1;
for( wPos = 2; isAlternating && wPos <= length( word ); wPos ++ )
{
hadVowel = haveVowel;
haveVowel = substr( word, wPos, 1 ) ~ /^[aeiou]/;
isAlternating = ( hadVowel && ! haveVowel ) || ( ! hadVowel && haveVowel );
} # for wPos
if( isAlternating )
{
printf( " %16s%s", word, ( alternatingCount % 6 == 5 ) ? "\n" : "" );
alternatingCount += 1;
} # if isAlternating
}
 
END \
{
printf( "\n%d words with alternating vowels and consonants found\n", alternatingCount );
} # END
Output:
       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 with alternating vowels and consonants found

C[edit]

#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
#define MAX_WORD_SIZE 80
 
bool is_vowel(char ch) {
switch (ch) {
case 'a': case 'A':
case 'e': case 'E':
case 'i': case 'I':
case 'o': case 'O':
case 'u': case 'U':
return true;
}
return false;
}
 
int main(int argc, char** argv) {
const char* filename = argc < 2 ? "unixdict.txt" : argv[1];
FILE* fp = fopen(filename, "r");
if (!fp) {
perror(filename);
return EXIT_FAILURE;
}
char line[MAX_WORD_SIZE];
int n = 1;
while (fgets(line, sizeof(line), fp)) {
size_t len = strlen(line) - 1; // last character is \n
if (len <= 9)
continue;
bool is_odd_even_word = true;
for (size_t i = 1; i < len; ++i) {
if (is_vowel(line[i]) == is_vowel(line[i - 1])) {
is_odd_even_word = false;
break;
}
}
if (is_odd_even_word)
printf("%2d: %s", n++, line);
}
fclose(fp);
return EXIT_SUCCESS;
}
Output:
 1: aboriginal
 2: apologetic
 3: bimolecular
 4: borosilicate
 5: calorimeter
 6: capacitate
 7: capacitive
 8: capitoline
 9: capitulate
10: caricature
11: colatitude
12: coloratura
13: colorimeter
14: debilitate
15: decelerate
16: decolonize
17: definitive
18: degenerate
19: deliberate
20: demodulate
21: denominate
22: denotative
23: deregulate
24: desiderata
25: desideratum
26: dilapidate
27: diminutive
28: epigenetic
29: facilitate
30: hemosiderin
31: heretofore
32: hexadecimal
33: homogenate
34: inoperative
35: judicature
36: latitudinal
37: legitimate
38: lepidolite
39: literature
40: locomotive
41: manipulate
42: metabolite
43: nicotinamide
44: oratorical
45: paragonite
46: pejorative
47: peridotite
48: peripatetic
49: polarimeter
50: recitative
51: recuperate
52: rehabilitate
53: rejuvenate
54: remunerate
55: repetitive
56: reticulate
57: savonarola
58: similitude
59: solicitude
60: tananarive
61: telekinesis
62: teratogenic
63: topologize
64: unilateral
65: unimodular
66: uninominal
67: verisimilitude

C++[edit]

#include <cstdlib>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <string>
 
bool is_vowel(char ch) {
switch (ch) {
case 'a': case 'A':
case 'e': case 'E':
case 'i': case 'I':
case 'o': case 'O':
case 'u': case 'U':
return true;
}
return false;
}
 
int main(int argc, char** argv) {
const char* filename = argc < 2 ? "unixdict.txt" : argv[1];
std::ifstream in(filename);
if (!in) {
std::cerr << "Cannot open file '" << filename << "'.\n";
return EXIT_FAILURE;
}
std::string line;
for (int n = 1; getline(in, line); ) {
size_t len = line.size();
if (len <= 9)
continue;
bool is_odd_even_word = true;
for (size_t i = 1; i < len; ++i) {
if (is_vowel(line[i]) == is_vowel(line[i - 1])) {
is_odd_even_word = false;
break;
}
}
if (is_odd_even_word)
std::cout << std::setw(2) << n++ << ": " << line << '\n';
}
return EXIT_SUCCESS;
}
Output:
 1: aboriginal
 2: apologetic
 3: bimolecular
 4: borosilicate
 5: calorimeter
 6: capacitate
 7: capacitive
 8: capitoline
 9: capitulate
10: caricature
11: colatitude
12: coloratura
13: colorimeter
14: debilitate
15: decelerate
16: decolonize
17: definitive
18: degenerate
19: deliberate
20: demodulate
21: denominate
22: denotative
23: deregulate
24: desiderata
25: desideratum
26: dilapidate
27: diminutive
28: epigenetic
29: facilitate
30: hemosiderin
31: heretofore
32: hexadecimal
33: homogenate
34: inoperative
35: judicature
36: latitudinal
37: legitimate
38: lepidolite
39: literature
40: locomotive
41: manipulate
42: metabolite
43: nicotinamide
44: oratorical
45: paragonite
46: pejorative
47: peridotite
48: peripatetic
49: polarimeter
50: recitative
51: recuperate
52: rehabilitate
53: rejuvenate
54: remunerate
55: repetitive
56: reticulate
57: savonarola
58: similitude
59: solicitude
60: tananarive
61: telekinesis
62: teratogenic
63: topologize
64: unilateral
65: unimodular
66: uninominal
67: verisimilitude

Factor[edit]

Works with: Factor version 0.99 2020-08-14
USING: grouping.extras io.encodings.ascii io.files kernel math
prettyprint sequences ;
 
"unixdict.txt" ascii file-lines
[ length 9 > ] filter
[ dup [ "aeiou" member? ] group-by [ length ] [email protected] = ] filter .
Output:
{
    "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"
}

Go[edit]

package main
 
import (
"bytes"
"fmt"
"io/ioutil"
"log"
"strings"
"unicode/utf8"
)
 
func isVowel(c rune) bool { return strings.ContainsRune("aeiou", c) }
 
func main() {
wordList := "unixdict.txt"
b, err := ioutil.ReadFile(wordList)
if err != nil {
log.Fatal("Error reading file")
}
bwords := bytes.Fields(b)
var words []string
for _, bword := range bwords {
s := string(bword)
if utf8.RuneCountInString(s) > 9 {
words = append(words, s)
}
}
count := 0
fmt.Println("Words with alternate consonants and vowels in", wordList, "\b:\n")
for _, word := range words {
found := true
for i, c := range word {
if (i%2 == 0 && isVowel(c)) || (i%2 == 1 && !isVowel(c)) {
found = false
break
}
}
if !found {
found = true
for i, c := range word {
if (i%2 == 0 && !isVowel(c)) || (i%2 == 1 && isVowel(c)) {
found = false
break
}
}
}
if found {
count++
fmt.Printf("%2d: %s\n", count, word)
}
}
}
Output:
Words with alternate consonants and vowels in unixdict.txt:

 1: aboriginal
 2: apologetic
 3: bimolecular
 4: borosilicate
 5: calorimeter
 6: capacitate
 7: capacitive
 8: capitoline
 9: capitulate
10: caricature
11: colatitude
12: coloratura
13: colorimeter
14: debilitate
15: decelerate
16: decolonize
17: definitive
18: degenerate
19: deliberate
20: demodulate
21: denominate
22: denotative
23: deregulate
24: desiderata
25: desideratum
26: dilapidate
27: diminutive
28: epigenetic
29: facilitate
30: hemosiderin
31: heretofore
32: hexadecimal
33: homogenate
34: inoperative
35: judicature
36: latitudinal
37: legitimate
38: lepidolite
39: literature
40: locomotive
41: manipulate
42: metabolite
43: nicotinamide
44: oratorical
45: paragonite
46: pejorative
47: peridotite
48: peripatetic
49: polarimeter
50: recitative
51: recuperate
52: rehabilitate
53: rejuvenate
54: remunerate
55: repetitive
56: reticulate
57: savonarola
58: similitude
59: solicitude
60: tananarive
61: telekinesis
62: teratogenic
63: topologize
64: unilateral
65: unimodular
66: uninominal
67: verisimilitude

Haskell[edit]

import Data.List.Split (chunksOf)
 
------ WORDS WITHOUT SUCCESSIVE VOWELS OR CONSONANTS -----
 
isLongAlternator :: String -> Bool
isLongAlternator s =
9 < length s
&& all (\(a, b) -> isVowel a /= isVowel b) (zip s $ tail s)
 
isVowel :: Char -> Bool
isVowel = flip elem "aeiou"
 
--------------------------- TEST -------------------------
main :: IO ()
main =
readFile "unixdict.txt"
>>= mapM_ putStrLn
. ( ((:) . (<> " matching words:\n") . show . length)
<*> inColumns 4
)
. filter isLongAlternator
. lines
 
------------------------ FORMATTING ----------------------
 
inColumns :: Int -> [String] -> [String]
inColumns n xs = unwords <$> chunksOf n (justifyLeft w ' ' <$> xs)
where
w = maximum (length <$> xs)
 
justifyLeft :: Int -> Char -> String -> String
justifyLeft n c s = take n (s <> replicate n c)
Output:
67 matching words:

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

Julia[edit]

See Alternade_words#Julia for the foreachword function.

isvowel(c) = c in ['a', 'e', 'i', 'o', 'u'] # NB. leaves out 'α' and similar unicode vowels, and what about y?
onlyodds(f, s) = all(c -> f(c), s[1:2:length(s)]) && !any(c -> f(c), s[2:2:length(s)])
onlyevens(f, s) = !any(c -> f(c), s[1:2:length(s)]) && all(c -> f(c), s[2:2:length(s)])
eitheronlyvowels(w, _) = onlyodds(isvowel, w) || onlyevens(isvowel, w) ? w : ""
 
foreachword("unixdict.txt", eitheronlyvowels, minlen = 10)
 
Output:
Word source: unixdict.txt

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

Perl[edit]

Translated from AWK[edit]

Used a2p.

Translation of: AWK
# 20210104 added Perl programming solution
 
use strict;
use warnings;
 
my $alternatingCount = 0;
 
while (<>) {
(my $Fld1) = split(' ', $_, -1);
if ((length($Fld1) >= 10)) { # have an arpropriate length word
my $word = $Fld1;
my $haveVowel = $word =~ /^[aeiou]/;
my $isAlternating = 1;
for (my $wPos = 2; $isAlternating && $wPos <= length($word); $wPos++) {
my $hadVowel = $haveVowel;
$haveVowel = substr($word, ($wPos)-1, 1) =~ /^[aeiou]/;
$isAlternating = ($hadVowel && !$haveVowel) || (!$hadVowel && $haveVowel);
} # for wPos
if ($isAlternating) {
printf ' %16s%s', $word, ($alternatingCount % 6 == 5) ? "\n" : '';
$alternatingCount += 1;
} # if isAlternating
}
}
 
printf "\n%d words with alternating vowels and consonants found\n", $alternatingCount;
Output:
       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 with alternating vowels and consonants found

Regex solution[edit]

I've heard rumors that there are more than 5 vowels...

$vowels = 'aeiou';
$v = qr/[$vowels]/;
$c = qr/[^$vowels]/;
 
/^ ( ($c$v)+ $c? | ($v$c)+ $v? ) $/ix and say for grep { /.{10}/ } split "\n", do { (@ARGV, $/) = 'unixdict.txt'; <> };
Output:
aboriginal
apologetic
bimolecular
...
verisimilitude

Phix[edit]

Not even slightly challenging, or in any way possibly ever useful, or the slightest bit interesting.... Yawneroo.

function odd(integer idx) return remainder(idx,2)=1 end function
function vowel(integer ch) return find(ch,"aeiou")!=0 end function
function oddeven(string word)
if length(word)<=9 then return false end if
sequence consonants = apply(word,vowel),
ohoneohone = apply(tagset(length(word)),odd)
return find(consonants,{ohoneohone,sq_not(ohoneohone)})
end function
sequence words = filter(get_text("demo/unixdict.txt",GT_LF_STRIPPED),oddeven)
printf(1,"%d olacelavovv words found: %s\n",{length(words),join(shorten(words,"",3),", ")})
Output:
67 olacelavovv words found: aboriginal, apologetic, bimolecular, ..., unimodular, uninominal, verisimilitude

Plain English[edit]

To run:
Start up.
Put "c:\unixdict.txt" into a path.
Read the path into a buffer.
Slap a rider on the buffer.
Loop.
Move the rider (text file rules).
Subtract 1 from the rider's token's last. \remove the newline
Put the rider's token into a word string.
If the word is blank, break.
If the word's length is less than 10, repeat.
If the word is alternating between vowels and consonants, write the word on the console.
Repeat.
Wait for the escape key.
Shut down.
 
To decide if a string is alternating between vowels and consonants:
Slap a substring on the string.
Put the substring's first plus 1 into the substring's last.
Loop.
If the substring's last's target is noise, say yes.
If the substring is double, say no.
Add 1 to the substring's first.
Add 1 to the substring's last.
Repeat.
 
To decide if a string is double:
If the string's first's target is any consonant, set a flag.
If the string's last's target is any consonant, set another flag.
If the flag is the other flag, say yes.
Say no.
Output:
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

Raku[edit]

Sigh. Yet another "Filter a word list" task. In a effort to make it a little more interesting, rather than just doing a one-liner, build a grammar and use that to filter.

grammar VOWCON {
token TOP { <|w> <vowel>? ( <consonant> <vowel> )* <consonant>? <|w> }
token vowel { <[aeiou]> }
token consonant { <[a..z] - [aeiou]> }
}
 
say ( grep { VOWCON.parse: .lc }, grep { .chars > 9 }, 'unixdict.txt'.IO.words ).batch(6)».fmt('%-15s').join: "\n";
Output:
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

REXX[edit]

/*REXX program finds all the  caseless words  (within an identified dictionary)  that   */
/*───────── either have odd letters that are vowels, and even letters that consonants, */
/*───────── or vice versa. */
parse arg minL iFID . /*obtain optional arguments from the CL*/
if minL=='' | minL=="," then minL= 10 /*Not specified? Then use the default.*/
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
finds= 0 /*count of the words found (so far). */
vow= 'AEIOU' /*the list of vowels. */
con= 'BCDFGHJKLMNPQRSTVWXYZ' /* " " " consonants. */
@@@= /* " " " 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; uppercase it. */
ovec= 1; ocev= 1 /*initialize both test cases as passed.*/
 
do ov=1 by 2 to L /*only scan odd indexed letters in word*/
z= substr(y, ov, 1) /*examine the odd letters in the word. */
if verify(z, vow)>0 then ovec= 0 /*Odd letter not a vowel? Then flunk. */
end /*k*/
 
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.*/
end /*out*/
 
if _\=='' then say substr(_, 2) /*Any residual words? Then show a line*/
output   when using the default inputs:
────────────────────────────── 25104 words in the dictionary file:  unixdict.txt

────────────────────────────── 67  words found with a minimum length of  10
    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

Ring[edit]

 
cStr = read("unixdict.txt")
wordList = str2list(cStr)
words = []
num = 0
vowels = "aeiou"
consonants = "bcdfghjklmnpqrstvwxyz"
 
see "working..." + nl
 
ln = len(wordList)
for n = ln to 1 step -1
if len(wordList[n]) < 10
del(wordList,n)
ok
next
 
see "Words are:" + nl + nl
 
for n = 1 to len(wordList)
cflag = 0
vflag = 0
len = len(wordList[n])
for m = 1 to len
if m % 2 = 1
cons = substr(consonants,wordList[n][m])
if cons > 0
cflag = 1
else
cflag = 0
exit
ok
ok
if m % 2 = 0
cons = substr(vowels,wordList[n][m])
if cons > 0
vflag = 1
else
vflag = 0
exit
ok
ok
next
if cflag = 1 and vflag = 1
add(words,wordList[n])
ok
next
 
for n = 1 to len(wordList)
cflag = 0
vflag = 0
len = len(wordList[n])
for m = 1 to len
if m % 2 = 1
cons = substr(vowels,wordList[n][m])
if cons > 0
cflag = 1
else
cflag = 0
exit
ok
ok
if m % 2 = 0
cons = substr(consonants,wordList[n][m])
if cons > 0
vflag = 1
else
vflag = 0
exit
ok
ok
next
if cflag = 1 and vflag = 1
add(words,wordList[n])
ok
next
 
words = sort(words)
 
for n = 1 to len(words)
see "" + n + ". " + words[n] + nl
next
 
see "done..." + nl
 

Output:

working...
Words are:

1. aboriginal
2. apologetic
3. bimolecular
4. borosilicate
5. calorimeter
6. capacitate
7. capacitive
8. capitoline
9. capitulate
10. caricature
11. colatitude
12. coloratura
13. colorimeter
14. debilitate
15. decelerate
16. decolonize
17. definitive
18. degenerate
19. deliberate
20. demodulate
21. denominate
22. denotative
23. deregulate
24. desiderata
25. desideratum
26. dilapidate
27. diminutive
28. epigenetic
29. facilitate
30. hemosiderin
31. heretofore
32. hexadecimal
33. homogenate
34. inoperative
35. judicature
36. latitudinal
37. legitimate
38. lepidolite
39. literature
40. locomotive
41. manipulate
42. metabolite
43. nicotinamide
44. oratorical
45. paragonite
46. pejorative
47. peridotite
48. peripatetic
49. polarimeter
50. recitative
51. recuperate
52. rehabilitate
53. rejuvenate
54. remunerate
55. repetitive
56. reticulate
57. savonarola
58. similitude
59. solicitude
60. tananarive
61. telekinesis
62. teratogenic
63. topologize
64. unilateral
65. unimodular
66. uninominal
67. verisimilitude
done...


Ruby[edit]

VOWELS =%w(a e i o u).map(&:freeze)
 
res = File.open("unixdict.txt").each_line.select do |line|
word = line.chomp
word.size > 9 && word.chars.each_cons(2).all?{|c1, c2| VOWELS.include?(c1) != VOWELS.include?(c2) }
end
puts res
Output:
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

Swift[edit]

import Foundation
 
func isVowel(_ char: Character) -> Bool {
switch (char) {
case "a", "A", "e", "E", "i", "I", "o", "O", "u", "U":
return true
default:
return false
}
}
 
do {
let words = try String(contentsOfFile: "unixdict.txt", encoding: String.Encoding.ascii)
var n = 1
for word in words.components(separatedBy: "\n") {
if word.count <= 9 {
continue
}
var isOddEvenWord = true
var prev: Character = "\n"
for ch in word {
if prev != "\n" && isVowel(ch) == isVowel(prev) {
isOddEvenWord = false
break
}
prev = ch
}
if isOddEvenWord {
print("\(String(format: "%2d", n)): \(word)")
n += 1
}
}
} catch {
print(error.localizedDescription)
}
Output:
 1: aboriginal
 2: apologetic
 3: bimolecular
 4: borosilicate
 5: calorimeter
 6: capacitate
 7: capacitive
 8: capitoline
 9: capitulate
10: caricature
11: colatitude
12: coloratura
13: colorimeter
14: debilitate
15: decelerate
16: decolonize
17: definitive
18: degenerate
19: deliberate
20: demodulate
21: denominate
22: denotative
23: deregulate
24: desiderata
25: desideratum
26: dilapidate
27: diminutive
28: epigenetic
29: facilitate
30: hemosiderin
31: heretofore
32: hexadecimal
33: homogenate
34: inoperative
35: judicature
36: latitudinal
37: legitimate
38: lepidolite
39: literature
40: locomotive
41: manipulate
42: metabolite
43: nicotinamide
44: oratorical
45: paragonite
46: pejorative
47: peridotite
48: peripatetic
49: polarimeter
50: recitative
51: recuperate
52: rehabilitate
53: rejuvenate
54: remunerate
55: repetitive
56: reticulate
57: savonarola
58: similitude
59: solicitude
60: tananarive
61: telekinesis
62: teratogenic
63: topologize
64: unilateral
65: unimodular
66: uninominal
67: verisimilitude

Wren[edit]

Library: Wren-fmt
import "io" for File
import "/fmt" for Fmt
 
var isVowel = Fn.new { |c| "aeiou".contains(c) }
 
var wordList = "unixdict.txt" // local copy
var words = File.read(wordList).trimEnd().split("\n").where { |w| w.count > 9 }
var count = 0
System.print("Words with alternate consonants and vowels in %(wordList):\n")
for (word in words) {
var found = true
for (i in 0...word.count) {
var c = word[i]
if ((i%2 == 0 && isVowel.call(c)) || (i%2 == 1 && !isVowel.call(c))) {
found = false
break
}
}
if (!found) {
found = true
for (i in 0...word.count) {
var c = word[i]
if ((i%2 == 0 && !isVowel.call(c)) || (i%2 == 1 && isVowel.call(c))) {
found = false
break
}
}
}
if (found) {
count = count + 1
Fmt.print("$2d: $s", count, word)
}
}
Output:
Words with alternate consonants and vowels in unixdict.txt:

 1: aboriginal
 2: apologetic
 3: bimolecular
 4: borosilicate
 5: calorimeter
 6: capacitate
 7: capacitive
 8: capitoline
 9: capitulate
10: caricature
11: colatitude
12: coloratura
13: colorimeter
14: debilitate
15: decelerate
16: decolonize
17: definitive
18: degenerate
19: deliberate
20: demodulate
21: denominate
22: denotative
23: deregulate
24: desiderata
25: desideratum
26: dilapidate
27: diminutive
28: epigenetic
29: facilitate
30: hemosiderin
31: heretofore
32: hexadecimal
33: homogenate
34: inoperative
35: judicature
36: latitudinal
37: legitimate
38: lepidolite
39: literature
40: locomotive
41: manipulate
42: metabolite
43: nicotinamide
44: oratorical
45: paragonite
46: pejorative
47: peridotite
48: peripatetic
49: polarimeter
50: recitative
51: recuperate
52: rehabilitate
53: rejuvenate
54: remunerate
55: repetitive
56: reticulate
57: savonarola
58: similitude
59: solicitude
60: tananarive
61: telekinesis
62: teratogenic
63: topologize
64: unilateral
65: unimodular
66: uninominal
67: verisimilitude