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]

Advertisements

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([0])
    

    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.

    Enigma 1342 - Solution

    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
    

Leave a Comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: