Enigmatic Code

Programming Enigma Puzzles

Enigma 1324: Rhombic squares

From New Scientist #2483, 22nd January 2005

Imagine you have two identical isosceles right-angled triangles. Lay one down so that one short side is horizontal and one is vertical. Lay the second one down so that a short side of the second is against a short side of the first, the two hypotenuses being parallel, so forming a rhombus, one example being as shown.

Enigma 1324

You are asked to place a digit at each of nine points, the four corners of the rhombus, the midpoint of each of the four sides, and the midpoint of the shorter diagonal such that eight numbers read horizontally and vertically from the top are all different perfect squares.

Alison and Bertha have each found a different solution. One of Alison’s two-digit squares is 81.

Which two did Bertha find?


4 responses to “Enigma 1324: Rhombic squares

  1. Jim Randell 16 May 2014 at 7:16 am

    This Python program finds possible sets of numbers that can be used to fill out the rhombus. It runs in 121ms.

    # there are four ways of joining the triangles, in one direction we
    # get three 3-digit squares, in the other direction we get one
    # 3-digit, two 2-digit and two 1-digit squares, making 8 squares
    # altogether
    # (1)     a b c
    #       d e f
    #     g h i
    # => abc, def, ghi, aei, dh, bf, g, c (as in the diagram)
    # (2) a b c
    #       d e f
    #         g h i
    # => abc, def, ghi, ceg, bd, fh, a, i
    # (3) a
    #     b d
    #     c e g
    #       f h
    #         i
    # => abc, def, ghi, ceg, bd, fh, a, i (same as (2))
    # (4)     g
    #       d h
    #     a e i
    #     b f
    #     c
    # => abc, def, ghi, aei, dh, bf, g, c (same as (1))
    # so there are essentially two different arrangements (as the other
    # two are just symmetries of existing solutions).
    from collections import defaultdict
    from itertools import count, product
    from enigma import printf
    # 1-, 2-, 3- digit squares (as strings)
    squares = defaultdict(list)
    for i in count(0):
      s = str(i * i)
      n = len(s)
      if  n > 3: break
    # choose three parallel 3-digit squares
    for (s1, s2, s3) in product(squares[3], repeat=3):
      # there are two different ways of arranging the triangles
      a1 = (s1, s2, s3, s1[0] + s2[1] + s3[2], s2[0] + s3[1], s1[1] + s2[2], s3[0], s1[2])
      a2 = (s1, s2, s3, s1[2] + s2[1] + s3[0], s1[1] + s2[0], s2[2] + s3[1], s1[0], s3[2])
      for a in (a1, a2):
        # all numbers must be distinct
        if len(set(a)) != len(a): continue
        # all numbers must be squares
        if not all(x in squares[len(x)] for x in a[3:]): continue
        printf("[{s1} {s2} {s3}] => {a}", a=sorted(int(x) for x in a))

    Solution: Bertha’s two-digit squares are 16 and 81.

    I’ve marked this puzzle as flawed, as I feel that the problem statement requires clarification.

    Clearly there’s something odd going on as we are not simply asked to fill out numbers in the diagram, but the diagram shows “one example” of the arrangement of the triangles to make a rhombus. There are actually 4 possible arrangements of the triangles, but two of them are rotated mirror images of the other two and give rise to the same set of squares.

    We are not told what constitutes a solution to the puzzle as far as Alison and Bertha are concerned. The implication is that the set of 8 different perfect squares should form the solution, but as the code above shows there is only one possible set of squares that can be produced. So the only possible solution is that Alison and Bertha found the same set of squares (so the statement “one of Alison’s two-digit squares is 81” is unnecessary, and is actually misleading as we might naturally assume that this means Bertha’s solution does not include 81), but laid them out differently so that they are considered different solutions. But however we resolve the fact that Alison and Bertha’s solutions are different, the only possible outcome for Bertha’s two-digit squares is 16 and 81.

    Here are the two different layouts of the solution, that could be Alison and Bertha’s solutions:

    Enigma 1324 - Solution

    If we relax the condition that all the squares be distinct (by removing line 56 in the program), we find that there are 6 different sets of squares that can be generated, and only the one given above has the square 81 in it.

    • Anonymous Coward 22 August 2016 at 9:44 am

      I think you have missed a couple of valid solutions in the above write-up, both of form (2) per the comments in your code.

      The first missing solution has the three-digit numbers 169, 400 and 049 along its rows, reading from top to bottom. The corresponding column-values (from left to right) are: 1, 64, 900, 04 and 9.

      The second missing solution has the three-digit numbers 900, 441 and 961 along its rows, reading from top to bottom. The corresponding column-values (from left to right) are: 9, 04, 049, 16 and 1.

      • Jim Randell 22 August 2016 at 11:25 am

        Thanks for the comment.

        It is normal in Enigma puzzles for numbers with leading zeros to be disallowed. If we allow them in this puzzle (which doesn’t explicitly exclude them in the puzzle text, but I did exclude them in my program), then as well as the two additional solutions you give for arrangement (2) there are also three additional solutions for arrangement (1):

            1 0 0
          3 2 4
        9 6 1

        giving squares of: 100, 324, 961 (rows), and 9, 36, 121, 04, 0 (columns);

            4 0 0
          1 4 4
        9 6 1

        giving squares of: 400, 144, 961 (rows), and 9, 16, 441, 04, 0 (columns);

            4 8 4
          0 0 1
        9 0 0

        giving squares of: 484, 001, 900 (rows), and 9, 00, 400, 81, 4 (columns).

        If we allow these additional solutions then Alison and Bertha could have found different sets of squares, and if we use the condition “One of Alison’s two digit squares is 81” to attempt to eliminate those solutions containing 81, that still leaves us with four possible layouts for Bertha. Two of them have (04, 16) as the two-digit squares, and the remaining two have (04, 36) and (04, 64), so we still wouldn’t be able to deduce a unique solution to the problem.

        The published solution was that Bertha’s two-digit squares were 16 and 81, which supports the idea that the two different layouts of the single solution that doesn’t include squares with leading zeros are what the setter had in mind for Alison and Bertha.

  2. Hugh Casement 22 August 2016 at 11:13 am

    I would call that a reflexion of form 1.
    Are leading zeros allowed?  Not usually in such puzzles (unless specifically stated).

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: