Enigmatic Code

Programming Enigma Puzzles

Enigma 1752: Pentagon of squares

From New Scientist #2920, 8th June 2013 [link]

I have drawn a circle, marked five points around its circumference, and joined each to the next by a straight line in order to make a pentagon. It turns out that the centre of the circle is outside this pentagon. I have then measured, in degrees, the five interior angles of the pentagon. The five numbers are all different and all but the smallest are perfect squares.

What is the smallest angle and what are the angles on either side of the smallest one?

[enigma1752]

Advertisements

7 responses to “Enigma 1752: Pentagon of squares

  1. Jim Randell 5 June 2013 at 7:48 pm

    This Python program runs in 44ms. I’ll provide a diagram to explain the solution later.

    from itertools import permutations
    from enigma import irange, printf
    
    # there are two angles less than 90 degrees
    # and three angles less than 180 degrees
    # and they sum to 540 degrees
    
    # possible squares
    squares90 = list(i * i for i in irange(1, 9))
    squares180 = list(i * i for i in irange(10, 13))
    
    # choose an angle for f
    for f in irange(1, 89):
      # p1 = a - f is a square < 90
      for p1 in squares90:
        a = p1 + f
        if not(0 < a < 90): continue
        # p2 = a + b and p3 = b + c are different squares < 180
        for (p2, p3) in permutations(squares180, 2):
          b = p2 - a
          c = p3 - b
          d = 270 + f - (a + b + c)
          if not(0 < b < 90 and 0 < c < 90 and 0 < d < 90): continue
          # p4 = c + d is a square < 180
          p4 = c + d
          if p4 in (p2, p3) or p4 not in squares180: continue
          # p5 is not a square, and is the smallest angle
          p5 = 540 - (p1 + p2 + p3 + p4)
          if not(0 < p5 < p1) or p5 in squares90: continue
    
          printf("p5={p5} p1={p1} p4={p4} p2={p2} p3={p3} [f={f} a={a} b={b} c={c} d={d}]")
    

    Solution: The smallest angle is 42°. The angles on either side of it are 64° and 121°.

    • Jim Randell 5 June 2013 at 11:07 pm

      Here’s the diagram that explains my approach:

      Enigma 1752

      ABCDE is the pentagon inscribed in the circle centred on O.

      Radii from A, B, C, D, E to O form 4 isosceles triangles, so the angles at the vertices on the circumference of the circle for each triangle are the same – a, b, c, d, and on the triangle AEO the angles at the vertices on the circumference are both f.

      So we find the angles such that the internal angles of ABCDE at A, B, C, D are perfect squares – these angles are: a – f, a + b, b + c, c + d. The angle at E (the smallest angle) is d – f.

      Also the internal angles of the pentagon sum to 540°, so:

      540° = (a – f) + (a + b) + (b + c) + (c + d) + (d – f) = 2(a + b + c + d – f)

      hence:

      f = (a + b + c + d) – 270°

      And since (a + b) and (c + d) are integers, then so is f.

      • Jim Randell 6 June 2013 at 4:43 pm

        It’s more efficient to choose the squares and derive f. Although it only makes a minor difference to the runtime. This program’s overall run time is 40ms, but it examines many fewer options.

        from itertools import combinations, permutations
        from enigma import irange, printf
        
        # there are two angles less than 90 degrees (one of them a square)
        # and three angles less than 180 degrees (all of them square)
        # and they sum to 540 degrees
        
        # possible squares
        squares90 = list(i * i for i in irange(1, 9))
        squares180 = list(i * i for i in irange(10, 13))
        
        # choose the smallest square
        for p1 in squares90:
          # and choose three larger squares
          for s in combinations(squares180, 3):
            # the remaining (non-square) angle is...
            p5 = 540 - (p1 + sum(s))
            if not(0 < p5 < p1): continue
            if p5 in squares90: continue
            # order the three larger squares
            for (p2, p3, p4) in permutations(s):
              # f = (a + b) + (c + d) - 270, p2 = a + b, p4 = c + d
              f = (p2 + p4) - 270
              a = p1 + f
              b = p2 - a
              c = p3 - b
              d = p4 - c
              if not all(0 < x < 90 for x in (f, a, b, c, d)): continue
        
              printf("p5={p5} p1={p1} p4={p4} p2={p2} p3={p3} [a={a} b={b} c={c} d={d} f={f}]")
        
  2. Brian Gladman 5 June 2013 at 10:50 pm

    This uses a different approach

    from itertools import combinations, permutations
    
    # combine four different angles that are perfect squares
    for t4 in combinations((x * x for x in range(1, 14)), 4):
      # find the fifth (non square) included angle in the
      # pentagon and ensure that it is the smallest
      ee = 540 - sum(t4)
      if ee < min(t4):
        # now try all arrangements of the five angles
        for t5 in permutations(t4 + (ee,)):
          # and compute the angles subtended at the centre of the circle
          # by the four outer sides of the pentagon
          ang = [t5[i % 5] + t5[(i + 2) % 5] - 180 for i in range(1, 5)]
          # check that all these angles are greater than zero and that the
          # angle subtended by the fifth side at the centre is < 180
          if all(x > 0 for x in ang) and sum(ang) < 90:
            # find the position of the smallest angle
            ix = t5.index(ee)
            # and hence the positions of adjacent angles
            ix1, ix2 = (ix + 4) % 5, (ix + 1) % 5
            # avoid dual solutions
            if ix1 < ix2:
              u, v = sorted((t5[ix1], t5[ix2]))
              print('smallest = {:d}, adjacent = {:d} and {:d} {:s}, {:s}'
                        .format(ee, u, v, t5, ang))
    
  3. saracogluahmet 6 June 2013 at 6:23 pm
    squares=[169,144,121,100,81,64,49,36,25,16,9,4,1]
    
    def pentagon():
        while(True):
            possibles=[squares[0],squares[1],squares[2]]
            for i in range(3):
                F=possibles[i]
                possibles.remove(F)
                x1x2=180-F
                for j in range(3):
                    if i!=j:
                        S=possibles[j]
                        possibles.remove(S)
                        x3x4=180-S
                        HT=x1x2+x3x4
                        if HT<90:
                            for k in range(len(squares)):
                                sqr=squares[k]
                                if sqr<HT:
                                    remain=540-(F+S+sqr)
                                    popped=possibles.pop()
                                    remain=remain-popped
                                    if remain<sqr:
                                        print(remain,F,S,popped,sqr)
                                        return
                                    
                               
                            
    pentagon()
    
    • saracogluahmet 6 June 2013 at 6:28 pm

      My approach is totally different, I guess, before coding the enigma, I calculated the possible maximum 3 angles, and after having determined the limits of those values, and checking the center angle of the circle, I did write the code, I think this is enough fast

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: