Sunday Times Teaser 2764 – Three Little Lists
by Victor Bryant
Published: 13 September 2015 (link)
I have chosen five different numbers, each less than 20, and I have listed these numbers in three ways. In the first list the numbers are in increasing numerical order. In the second list the numbers are written in words and are in alphabetical order. In the third list they are again in words and as you work down the list each word uses more letters than its predecessor. Each number is in a different position in each of the lists.
What are my five numbers?
One Comment
Leave one →
-
Brian Gladman permalink12345678910111213141516171819202122232425262728293031323334from itertools import combinations# the numbers as wordsalpha = ('zero', 'one', 'two', 'three', 'four', 'five','six', 'seven', 'eight', 'nine', 'ten', 'eleven','twelve', 'thirteen', 'fourteen', 'fifteen','sixteen', 'seventeen', 'eighteen', 'nineteen')# choose the five numbers (assumed not to include zero)for n5 in combinations(range(1, 20), 5):# list them as words in alphabetical ordera5 = tuple(sorted(alpha[i] for i in n5))# and as words in order of word lengthl5 = tuple(sorted((alpha[i] for i in n5), key=len))# ensure that all the lengths are differentif len(set(len(x) for x in l5)) != 5:continue# find the positions of the numbers in the listsia5 = tuple(alpha.index(i) for i in a5)il5 = tuple(alpha.index(i) for i in l5)# compare the positions in the lists two at a time# and skip number choices with numbers in the same# position in any of the listsif all(all(x != y for x, y in zip(a, b))for a, b in combinations((n5, ia5, il5), 2)):# print the five numbers chosenprint('{}n{}n{}'.format(n5, a5, l5))