Enigmatic Code

Programming Enigma Puzzles

Puzzle #23: Circling the squares

From New Scientist #3249, 28th September 2019 [link] [link]

Darts player Juan Andred has noticed that on a standard dartboard, there are some neighbouring pairs of numbers that add up to a square number. For example, 20 and 5 make 25, while 6 and 10 add up to 16. He has been wondering if he can come up with a new arrangement of the numbers 1 to 20 so that all neighbouring pairs add up to a square number. And he has nearly succeeded.

He has 20 at the top of the board, and every pair of neighbours adds to a square — with one exception. On his new board, 18 doesn’t form a square with its clockwise neighbour, which is 15, or with its anticlockwise neighbour.

What does Juan’s “square” dartboard look like?

[puzzle#23]

4 responses to “Puzzle #23: Circling the squares

  1. Jim Randell 28 September 2019 at 8:12 am

    There are two solutions to this puzzle.

    The following Python 3 program finds them in 93ms.

    Run: [ @repl.it ]

    from enigma import is_square, cached, diff, irange, tuples, join
    
    is_square = cached(is_square)
    
    # form a chain of pairs that sum squares
    def solve(s, ns):
      if not ns:
        yield s
      else:
        x = s[-1]
        # choose the next number
        for (i, n) in enumerate(ns):
          if is_square(x + n):
            yield from solve(s + [n], ns[:i] + ns[i + 1:])
    
    # find a chain that solves the puzzle
    for s in solve([15], diff(irange(1, 20), [15, 18])):
      # put 18 in at the start
      s.insert(0, 18)
      # split the list at 20
      i = s.index(20)
      s = s[i:] + s[:i] + [20]
      # indicate if the pairs form squares (+ if they do, - if they don't)
      j = list("-+"[bool(is_square(a + b))] for (a, b) in tuples(s, 2)) + [""]
      print(join((join((a, b), sep=" ") for (a, b) in zip(s, j)), sep=" "))
    

    Solution: There are two options:

    [20 – 18 – 15 + 10 + 6 + 19 + 17 + 8 + 1 + 3 + 13 + 12 + 4 + 5 + 11 + 14 + 2 + 7 + 9 + 16 + 20]
    [20 + 16 + 9 + 7 + 2 + 14 + 11 – 18 – 15 + 10 + 6 + 19 + 17 + 8 + 1 + 3 + 13 + 12 + 4 + 5 + 20]

    Where + indicates the sum of adjacent pairs sums to a square and – indicates that it doesn’t.

    There are two chains which we fit together. The first starts with 18 and its clockwise partner 15:

    [18 – 15 + 10 + 6 + 19 + 17 + 8 + 1 + 3 + 13 + 12 + 4 + 5]

    We can then form the remaining numbers into the following chain:

    [11 + 14 + 2 + 7 + 9 + 16 + 20]

    Which we can join to the 5 from either end (as we don’t have to worry about forming a square with 18 when the loop is closed).

    This gives the two possible board layouts.

    • Jim Randell 3 October 2019 at 12:50 pm

      The officially published solution only gives one answer:

      [20 + 16 + 9 + 7 + 2 + 14 + 11 – 18 – 15 + 10 + 6 + 19 + 17 + 8 + 1 + 3 + 13 + 12 + 4 + 5 + 20]

      (The second of the answers I give).

      It doesn’t find the other one as it appears to be based on faulty reasoning as it makes the claim that the anticlockwise neighbour of 18 must be 11.


      In the 9th November 2019 issue of New Scientist, the following was published:

      There is at least one other rearrangement of a dartboard in which each neighbouring pair adds up to a square number: 20, 18, 15, 10, 6, 19, 17, 8, 1, 3, 13, 12, 4, 5, 11, 14, 2, 7, 9, 16.
      (Puzzle, 28 September; solution 5 October)

      They seem to be leaving the door open to additional solutions, but there are only two.

  2. Hugh Casement 29 September 2019 at 7:03 am

    It’s always 18 that’s the odd one out, but it doesn’t have to be followed by 15.
    We could reverse the order of the first six and get
    (18) 8, 17, 19, 6, 10, 15, then as before from 1 onward
    or the first twelve after 18 could be
    10, 15, 1, 8, 17, 19 in either order, then 6, 3, 13, 12, 4, 5.
    Of course any of the eight sequences could be completely reversed.
    Whether it makes for a better game of darts is open to doubt!

    • Jim Randell 29 September 2019 at 9:58 am

      @Hugh: Yes, 18 is always doomed to break the chain, as it can only link to 7 to make a square.

      But if we start with [18 + 7 + …] we can make chains of length length 17 leaving [9 + 16 + 20] or [2 + 14 + 11] to be joined in. But they can’t be linked together using squares, so there would still be 2 non-square links in a complete loop.

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 )

Google photo

You are commenting using your Google 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 )

Connecting to %s

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

%d bloggers like this: