# Enigmatic Code

Programming Enigma Puzzles

## Enigma 1342: GOSH

From New Scientist #2501, 28th May 2005

The latest work at GOSH, the Gallery of Shocking (H)artwork, consists of a straight line of pins nailed into the floor. The second pin is one centimetre from the first and (continuing in the same direction) each pin was as close as possible to the previous pin so that it is a whole number of centimetres from it and no pin is exactly mid-way between two others.

The total distance from the first to the last pin is between four and eight feet.

How many pins are there in this work of art?

[enigma1342]

### 2 responses to “Enigma 1342: GOSH”

1. Jim Randell 5 March 2014 at 7:50 am

This Python program solves the problem recursively. It runs in 40ms.

```from enigma import irange, printf

def solve(pins):
p = pins[-1]
# have we reached the target length?
if 121 < p < 244:
n = len(pins)
printf("{n} pins @ {pins}")
# try to add another pin
for q in irange(p + 1, 243):
# can we add this pin?
r = q % 2
if not any(x % 2 == r and (x + q) // 2 in pins for x in pins):
solve(pins + [q])
break

solve()
```

Solution: The artwork consists of 33 pins.

The position of the pins corresponds to the first 33 terms of sequence A005836 in OEIS [ https://oeis.org/A005836 ].

Here is a plot of the positions of the first 32 pins. Aesthetically I wouldn’t have bothered with the 33rd pin.

2. Paul 15 March 2014 at 3:05 pm

MMA solution

```Length[Select[Range[1, 244], DigitCount[#, 3, 2] == 0 &]]
33
```

This site uses Akismet to reduce spam. Learn how your comment data is processed.