**From New Scientist #2547, 15th April 2006**

I have taken a pack of 10 cards numbered 1 to 10 and dealt them face down, giving a pair of cards to each of the clever kids Andy, Bandy, Candy, Dandy and Endy. They each look at their two cards and will, in turn, have to declare: “power” if the sum of the two is a perfect square or cube; “prime” if the sum is a prime; “big” if the sum is more than 12; “consecutive” if the two numbers are consecutive. For example, if dealt the 4 and 5, at his turn the child would make two declarations: “power” and “consecutive”.

When I asked them in turn for their declarations I am told that Andy, Bandy, Candy and Dandy each have nothing to declare. At that stage Andy said that he knew one particular declaration that Endy was bound to make. Endy then announced *how many* declarations he was going to make. Then only Bandy and Candy could work out Endy’s pair.

What are Andy’s, Dandy’s and Endy’s pairs?

[enigma1387]

### Like this:

Like Loading...

This one is a bit tricky to decide what to record at each stage of the program, but once you’ve got the data structures sorted out the program itself is relatively straightforward. This Python program uses the [[

`filter2()`

]] function, recently added to theenigma.pylibrary, which is similar to Python’s built-in [[`filter()`

]] function, except it returns both a list of values for which the function is true and a second list of values where the function returned false. It runs in 46ms.Solution:Andy’s pair is (1, 5); Dandy’s pair is (2, 10); Endy’s pair is (6, 7).Andy predicts that Endy will declare “big”, and Endy in fact makes three declarations “prime, big, consecutive”. Bandy and Candy have the pairs (3, 9) and (4, 8), but we don’t know which is holding which. Dandy can’t determine Endy’s pair, as he can’t distinguish the actual scenario from Endy having (8, 9) and Bandy and Candy having (3, 7) and (4, 6). Although once he knows Bandy and Candy can work out Endy’s pair, Dandy should also be able to work it out also.