New Scientist Enigma 498 – Vowel Count
by Susan Denham
From Issue #1650, 4th February 1989
In this Enigma (from “vowel” above to “?” at the end) if you put in the right numbers (in words) in the spaces then there will be … a’s, …e’s, … i’s, … o’s and … u’s.
After the correct things are put in all the spaces, how many vowels will there be (“vowel” — very end “?” inclusive)?
One Comment
Leave one →
-
Brian Gladman permalink12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667# convert integers to wordsl_lo = ( '', 'one', 'two', 'three', 'four', 'five', 'six', 'seven','eight', 'nine', 'ten', 'eleven', 'twelve', 'thirteen','fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen','nineteen' )l_10 = ( 'twenty', 'thirty', 'forty', 'fifty', 'sixty', 'seventy','eighty', 'ninety')def int_as_words(x, commas=True, l=0):if x < 20:return l_lo[x] if x else 'zero'else:return (l_10[x // 10 - 2] + ('', ' ')[x % 10 > 0] + l_lo[x % 10])text = """Vowel Countby Susan DenhamIn this Enigma (from "vowel" above to "?" at the end) if youput in the right numbers (in words) in the spaces then therewill be *1* a's, *2* e's, *3* i's, *4* o's and *5* u's.After the correct things are put in all the spaces, how manyvowels will there be ("vowel" -- very end "?" inclusive)?"""# add vowel count words in (subs) to the text in (s)def update(s, subs):r = sfor j, w in enumerate(subs, 1):r = r.replace(f"*{j}*", w)return r# find numbers of vowels in the initial textA, E, I, O, U = base_counts = [text.lower().count(x) for x in 'aeiou']# consider reasonable count ranges for the five vowels, noting# that 'a' doesn't occur in the vowel counts expressed as wordsa, aw = A, int_as_words(A)for e in range(E, E + 10):ew = int_as_words(e)for i in range(I, I + 10):iw = int_as_words(i)for o in range(O, O + 5):ow = int_as_words(o)for u in range(U, U + 5):uw = int_as_words(u)# update the text with the vowel counts in wordswds = (aw, ew, iw, ow, uw)s = update(text.lower(), wds)# and count the vowels in the revised textc = [s.count(v) for v in 'aeiou']# if the count is correctif c == [a, e, i, o, u]:# output the vowel counts and the final textt = ', '.join([f'{c}:{n}' for c, n in zip('aeiou', c)])print(f"A total of {sum(c)} vowels ({t}):")ss = update(text, wds)p = ss.find("o's")print('-' * 60)print(ss[1:p] + '\n' + ss[p:-1])print('-' * 60)