### 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,818 hits

Advertisements

Programming Enigma Puzzles

13 March 2014

Posted by on **From New Scientist #2499, 14th May 2005**

Andy has a new game which he plays on his stairs. These are numbered 0 (ground) to 9 (landing). He places his teddy on stair 9 and writes 9 on his score card. He pushes teddy over the edge, notes which stair he ends up on and writes that number on his card. He pushes teddy again over the edge of the stair he is on and again writes down the number of the stair he ends up on. He repeats this until teddy reaches the ground, when he stops.

Andy’s score for a game is the sum of the numbers on his card. Andy played his game many times and kept all the score cards. When he looked at all the cards he found an amazing thing. If he looked at which of the stairs (8, 7, …, 1, 0) teddy had ended up on when pushed off stair 9, he found teddy ended up on each stair the same number of times. Further, if Andy looked at all the cards with any particular initial sequence, say, 9, 7, 6 he found that all the remaining stairs, here, 5, 4, 3, 2, 1, 0 occurred equally often as the stair upon which teddy ended up when pushed off the last stair of the initial sequence, here, 6.

What was the average of all Andy’s scores?

[enigma1340]

Advertisements

%d bloggers like this:

A bit of analysis gives a recursive function that can be used to determine the average score from a given step. In this program I use the

cached()function decorator from theenigma.pylibrary to avoid recalculation. It runs in 55ms.Solution:The average of Andy’s scores is 38231/2520, approximately 15.171.Here’s a second program I wrote that simulates 100 million random trials (poor Teddy!), and gets an answer of 15.171 in 19.6s (using PyPy), so it seems like the analysis is OK.