### Random Post

### Recent Posts

### Recent Comments

### Archives

### Categories

- article (11)
- enigma (1,158)
- misc (2)
- project euler (2)
- puzzle (40)
- site news (44)
- tantalizer (42)
- teaser (3)

### Site Stats

- 177,972 hits

Advertisements

Programming Enigma Puzzles

6 March 2012

Posted by on **From New Scientist #2717, 18th July 2009** [link]

My little nephew and I play a simple guessing game using an ordinary pack of cards. In the first round we lay seven cards face down and he has to guess how many are red cards (a number between 0 and 7). Then, likewise, I have to guess how many are black, but I must choose my number so that the two guesses do not add up to 7 (so that at least one of us will be wrong). Then, on turning the cards over, my nephew earns 1 point for each red card plus a bonus of 10 points if his guess was correct and I earn 1 point for each black card plus a bonus of 10 points if my guess was correct. Then in the second round we repeat the exercise with six cards, then in subsequent rounds with five, four, three, two and one card.

In a recent game I recorded cumulative totals throughout and I noticed that after each of six of the seven rounds, my nephew’s total divided by mine was a whole number, and these six whole numbers were all different. Indeed, there were three consecutive rounds after which these three whole numbers were consecutive and decreasing.

Give our cumulative totals after the round(s) when his total divided by mine was an odd number.

[enigma1554]

Advertisements

%d bloggers like this:

This is the first Enigma problem I tackled in Python (although I had previously coded a solution in Perl, prior to this I attempted Perl solutions for Enigma problems, but I wanted to try and learn Python). This version is a slightly modified version of my original Python code. It runs in 400ms.

Solution:The cumulative totals divide to give an odd number when you have scored 35 points and your nephew has scored 7 points.Here’s my original Perl 5 solution (which the above Python is based on). It runs in 660ms on the same machine, so it’s faster in Python.

I found a solution in which the cumulative scores in the third, fourth, and fifth rounds were 24 & 4, 35 & 7, 36 & 9 respectively. But I also found several where the cumulative scores in the fourth, fifth, and sixth rounds were 28 & 4, 30 & 5, 30 & 6, or else 30 & 2, 42 & 3, 52 & 4. Are those precluded by the terms of the puzzle?

In a round with

ncards the total number of points handed out isn(if no-one gets the bonus) orn + 10(if someone does win the bonus).So in the sixth round (with 2 cards) the points awarded must be 2 or 12.

Going from (30, 5) in round 5 to (30, 6) in round 6 the points are (0, 1), so this can’t be a sixth round score. Similarly, going from (42, 3) in round 5 to (52, 4) in round 6 the points are (10, 1), so this can’t be a sixth round score either.

The only possible scores (for the first six rounds) my program came up with are:

There are four possible scores in the final round with 1 card (0, 11), (1, 10), (10, 1), (11, 0) (someone always gets the bonus in the last round), so there are four possible final scores, but only in the fourth round is the

n/mratio odd.Thanks, Jim. BASICally I was doing it right, but there was a wee fault in my program — easy to overlook but it made all the difference. I now get the same result as you.