Task 1: Word Count
"Vowel Landmarks: Counting Words with Vocalic Boundaries!"
Given a list of words, count how many of them either start or end with a vowel (a, e, i, o, u).
The Strategy: Iterate through each word in the list. For each word, check if the first character or the last character matches a predefined set of vowels (case-insensitive). Increment a counter whenever a match is found and return the total count.
Perl Implementation
sub word_count ($words) {
my $count = 0;
for my $word (@$words) {
++$count if $word =~ /\A[aeiou]/i || $word =~ /[aeiou]\z/i;
}
return $count;
}
Python Implementation
def word_count(words: Sequence[str]) -> int:
VOWELS = set("aeiou")
count = 0
for word in words:
if not word: continue
lower = word.lower()
if lower[0] in VOWELS or lower[-1] in VOWELS:
count += 1
return count