Enigmatic Code

Programming Enigma Puzzles

Enigma 1704: Joe’s triangle

From New Scientist #2871, 30th June 2012 [link]

Joe drew a right-angled triangle on an A6 file card. He asked Penny to cut it out and then cut it in two to make two right-angled triangles. Then he asked her to cut each triangle in two to make four right-angled triangles in total. Now Joe’s triangle was very special. Penny found that the lengths of all the sides of all the triangles were a whole number of millimetres.

What was the area of the smallest triangle?

Note: An A6 card has dimensions of 105 mm × 148 mm.



9 responses to “Enigma 1704: Joe’s triangle

  1. Jim Randell 27 June 2012 at 5:16 pm

    The following Python program runs in 50ms.

    from enigma import irange, is_square, printf
    # find possible right-angled triangles that fit on an A6 card
    triangles = []
    for a in irange(1, 105):
      for b in irange(a + 1, 148):
        c = is_square(a * a + b * b)
        if c is None: continue
        triangles.append((a, b, c))
    # split a triangle into two
    def split(t):
      (a, b, c) = t
      # find triangles (a1, b1, c1), (a2, b2, c2) such that
      # a = c1, b = c2, c = a1 + b2, b1 = a2
      for (a1, b1, c1) in triangles:
        if a != c1: continue
        (a2, b2, c2) = (b1, c - a1, b)
        if (a2, b2, c2) not in triangles: continue
        yield ((a1, b1, c1), (a2, b2, c2))
    # t1 is the first triangle
    for t1 in triangles:
      # split it into two
      for (t2, t3) in split(t1):
        # and split each of these into two
        for (t4, t5) in split(t2):
          for (t6, t7) in split(t3):
            printf("triangles = {t1} {t2} {t3} {t4} {t5} {t6} {t7}")
            # and find the smallest triangle (by area)
            printf("min area = {m}", m=min(a * b // 2 for (a, b, c) in (t4, t5, t6, t7)))

    Solution: The area of the smallest triangle is 486 sq mm.

  2. arthurvause 27 June 2012 at 6:22 pm

    I’m not sure if the intention is to use the whole of the card in some way, but if not there are multiple solutions.

    • arthurvause 27 June 2012 at 6:37 pm

      No there aren’t. I missed one of the equations from the code:

      squares = {n*n:n for n in range(3,149)}
      for c in range(1,148):
        for a in range(3,c):
          if c*c-a*a in squares:
            for g in range(3,100):
              if a*a +g*g in squares:
                f=squares[a*a +g*g]
                for d in range(3,100):
                  if b*b+d*d in squares:
                    if (g+b)**2 + (a+d)**2 == (f+e)**2 and f**2 +c**2==(g+b)**2:
                      print a,b,c,d,e,f,g
  3. arthurvause 27 June 2012 at 8:43 pm

    More understandable code, and a picture:

    squares = {n*n:n for n in range(3,149)}
    pythags = [(x,y,squares[x*x+y*y]) for x in range(3,100) for y in range(3,100) if x*x+y*y in squares]
    for (a,b,c) in pythags:
      for (g,f) in [(y,z) for (x,y,z) in pythags if x==a]:
        for(d,e) in [(y,z) for (x,y,z) in pythags if x==b]:
          if (g+b)**2 + (a+d)**2 == (f+e)**2 and f**2 +c**2==(g+b)**2 and e**2 +c**2==(a+d)**2:
            print a,b,c,d,e,f,g
  4. Brian Gladman 28 June 2012 at 9:24 am

    Here is my solution:

    # All the triangles are scaled up copies of the same primitive triangle
    # (u, v, w) with u <= v and w^2 = u^2 + v^2.   The linear scale factors
    # for the three different internal triangles are u^2, u * v and v^2 and
    # that for the original triangle is (u^2 + v^2).   The A6 card limits v
    # to less than 6.
    fs = 'Area = {0:d}, sides = {1:s}'
    sq = { x ** 2: x for x in range(1, 11)}
    for u in range(1, 6):
      for v in range(u, 6):
        t = u ** 2 + v ** 2
        if t in sq:
          prim = (u, v, sq[t])
          scale = (u * u, u * v, v * v, u * u + v * v)
          sides = tuple(set(x * y for x in prim for y in scale))
          print(fs.format((u * u) ** 2 * (u * v // 2), sorted(sides))) 
  5. Brian Gladman 4 July 2012 at 5:17 pm

    Hi Claire-Louise,

    Yes, but it also has to have the four integer sided right angled angles triangles inside it and this is not possible

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: