### Random Post

### Recent Posts

### Recent Comments

### Archives

### Categories

- article (11)
- enigma (1,183)
- misc (2)
- project euler (2)
- puzzle (46)
- site news (46)
- tantalizer (49)
- teaser (3)

### Site Stats

- 184,820 hits

Advertisements

Programming Enigma Puzzles

4 December 2011

Posted by on **From New Scientist #2826, 20th August 2011** [link]

We have been playing our family board game again, where we use a board of 100 spaces numbered 0 to 99. A player starts with his counter on 0, throws a die, and moves forward the number of spaces shown. If he lands on a space marked with a square number he moves forward to the next square number (e.g. if he lands on 49 he jumps to 64). If he lands on a prime he moves back to the preceding prime (e.g. from 19 he returns to 17), except from 2, in which case he returns to 0.

Tom and I played a game. I threw first and moved to a point three times as far up the board as he did. In fact as we continued, my “score” after each throw always remained three times his. After five throws each my score reached 36. The total of all the numbers we had thrown was also 36.

In order, what five numbers did I throw?

[enigma1660]

Advertisements

%d bloggers like this:

The following Python code runs in 31ms.

Solution:The 5 numbers you threw are: 4, 6, 3, 6 and 1.The question is not asking for what Tom threw, but for what the author threw.

If Tom threw first 4, he would move to square 1 (as 4 is a perfect square, he moves to the next smaller perfect square). If he then throws 6, he moves to square 5 (as 7 is a prime, so he moves to the next smaller prime). But this means that the author is on square 15 (3 times Tom’s square) after just two throws, which is not possible.

Thanks for joining in. You’re right, I labelled the throws of the dice in the solution as Tom’s instead of “mine” in the solution (now edited to correct this).

But the rules of the game are that if you land on a perfect square you move to the next

highestperfect square, not the nextsmallest. (However if you land on a prime you do move to the next smallest prime).So the progress of the games described in the puzzle is:

1st throw: I throw 4 (2²), so I move to 9 (3²). Tom throws 5 (a prime) so moves back to 3 (the next lowest prime). I am at 9, Tom is at 3. I am three times further up the board than Tom.

2nd throw: I throw 6, which moves me to 15. Tom throws 4, which moves him to 7 (a prime), so he moves back to 5. I am at 15, Tom is at 5. I am three times further up the board than Tom.

3rd throw: I throw 3, which moves me to 18. Tom throws 1, which moves him to 6. I am at 18, Tom is at 6. I am three times further up the board than Tom.

4th throw: I throw 6, which moves me up to 24. Tom throws 2, which moves him to 8. I am at 24, Tom is at 8. I am three times further up the board than Tom.

5th throw: I throw 1, which moves me to 25 (5²), so I move up to 36 (6²). Tom throws 4, and so moves up to 12. I am at 36, Tom is at 12. I am three times further up the board than Tom.

My score is currently 36, and the sum of my throws is 4+6+3+6+1 = 20, the sum of Tom’s throws is 5+4+1+2+4 = 16, so the sum of all the throws is 36.

Thanks, Jim.

Yes, I also spotted my error about the squares. Thanks for that. Your posting then prompted me to take another look at what I was trying to do (I thought it would be fun to write a basic program to solve it) when I discovered not only the square mistake, but that I’d missed the mumber 3 in my list of primes!

What language is your code in? It looks very much more compact than what I used.

Nice to make contcat.

I’ve been using Python for the last couple of years, before that I used Perl. See http://www.python.org/ for more information.

Once you get used to the idea of using whitespace indents to delimit blocks (something I wasn’t too keen on initially) it’s actually quite nice and compact to code in. Plus it has a nice built-in set class that is very useful for Enigma puzzles, and the standard itertools module provides some useful functionality too.