SECTION 14 / 24

Count adjacent vowel pairs inside a word

1 min read
specially has the neighbouring vowels i–a. In aaa, two overlapping adjacent pairs occur.
specially has the neighbouring vowels i–a. In aaa, two overlapping adjacent pairs occur.
REAL COURSE DATA · BUILD AND UNPACK LISTS

Find adjacent vowel pairs

Follow one occurrence at a time. Choose another input to test empty lists, repeated IDs and different parameters.

Ready

CURRENT RECORD / VALUE

Ready to begin

No records have been processed. Start with Next step.

What we remember

Processed
0

Predict the next change, then step through the list. The original course records remain unchanged.

L = explode(Word)
Count = 0
while length(L) >= 2:
    if isVowel(first(L)) AND isVowel(first(rest(L))):
        Count = Count + 1
    L = rest(L)
return Count

Use the five-vowel convention a, e, i, o, u, ignoring case for this test. In specially, i is immediately followed by a, giving one match. The task counts PAIRS, not vowels: specially has other vowels but only one adjacent vowel pair.

Move one position after each test, so pairs may overlap. aaa has matches at positions 1–2 and 2–3: two pairs. If you instead want to count word cards that contain at least one matching pair, stop the inner word scan after its first match and increment a separate word counter once. An outer word loop and inner character loop process different levels.

Dots and hyphens are not vowels and interrupt adjacency in this raw character representation. Empty and one-character lists yield zero adjacent pairs. The algorithm does not infer pronunciation or vowel sounds.

Try it yourself

How many adjacent vowel pairs are in aaa?

Show explained answer

Two. The middle a participates in both neighbouring pairs.

Try it yourself

What differs between “count matching pairs” and “count words with a match”?

Show explained answer

One word can contain several matching pairs. A word-level count increments at most once per qualifying word.

Try it yourself

What loop guard prevents reading past the end?

Show explained answer

Require length(L) ≥ 2 before examining first(L) and first(rest(L)).

YOUR STUDY PROGRESS

Finished this section? Save your progress.

Back to top ↑