New Scientist Enigma 1006 – Booklist
by Susan Denham
From Issue #2161, 21st November 1998
I have just been looking at the top six best-selling books listed in today’s paper. They are numbers from 1 (for the best selling book) to 6, and after each book its position in last week’s list is given.
It turns out that the same six books were in the list last week. For each of the books I multiplied the number of last week’s, and I got six different answers.
Now, if you asked my the following questions — then you would get the same answer in each case:
1. How many primes are there in that list of six products?
2. How many perfect squares are there in that list of six products?
3. How many perfect cubes are there in that list of six products?
4. How many odd numbers are there in that list of six products?
5. How many of the six books are in a higher place this week than last?
For the books 1-6 this week, what (in that order) were their positions last week?
-
Brian Gladman permalink123456789101112131415161718from itertools import permutations# try all permutations of last week's positionsfor p in permutations((range(1, 7))):q = tuple(enumerate(p, 1))r = tuple(a * b for a, b in q)# count how many books match each of the conditionscounts = (sum((a == 1) ^ (b == 1) for a, b in q),sum(ab in {1, 4, 9, 16, 25, 36} for ab in r),sum(ab in {1, 8, 27} for ab in r),sum(ab & 1 for ab in r),sum(a < b for a, b in q))if len(set(counts)) == 1:print(p)