### Random Post

### Recent Posts

### Recent Comments

### Archives

### Categories

- article (11)
- enigma (1,367)
- misc (4)
- project euler (2)
- puzzle (90)
- puzzle# (48)
- site news (58)
- tantalizer (94)
- teaser (7)

### Site Stats

- 233,129 hits

Programming Enigma Puzzles

20 May 2019

Posted by on **From New Scientist #1652, 18th February 1989** [link]

The children at the village school have a number game they play. A child begins by writing a list of numbers across the page, with just one condition, that no number in the list may be bigger than the number of numbers in the list. The rest of the game involves writing a second list of numbers underneath the first; this is done in the following way. Look at the first number — that is, the left-hand one, as we always count from the left. Say it is 6, then find the sixth number in the list — counting from the left — and write that number in the first place in the second row — so it will go below the 6. Repeat for the second number in the list, and so on. In the following example, the top row was written down, and then playing the game gave the bottom row:

6, 2, 2, 7, 1, 4, 10, 8, 4, 2, 1 4, 2, 2, 10, 6, 7, 2, 8, 7, 2, 6The girls in the school use the game to decide which boys are their sweethearts. For example, Ann chose the list of numbers:

2, 3, 1, 5, 6, 4For a boy to become Ann’s sweetheart he has to write down a list of numbers, play the game, and end with Ann’s list on the bottom row.

Bea chose the list:

2, 3, 2, 1, 2and Cath the list:

3, 4, 5, 6, 7, 1, 2, 5, 7, 3, 6, 9Find all the lists, if any, which enable a boy to become the sweetheart of Ann, of Bea, and of Cath.

**Enigma 1736** is also called “Child’s play”.

[enigma500]

%d bloggers like this:

In this Python program I use [[

`dict()`

]] objects to hold the sequences, to simplify the use of 1-based indices. It runs in 241ms.Run:[ @repl.it ]Solution:For Ann any of these four lists will work: (3, 1, 2, 6, 4, 5); (4, 5, 6, 2, 3, 1); (5, 6, 4, 1, 2, 3); (6, 4, 5, 3, 1, 2). For Bea there are no lists that work. For Cath the following list works: (2, 3, 4, 5, 6, 7, 1, 4, 6, 2, 9, 11).There are 8 sequences that will give the second sequence given in the example: