Enigmatic Code

Programming Enigma Puzzles

Enigma 1569: Cardiology

From New Scientist #2732, 31st October 2009 [link]

Joe gave Penny a rectangular piece of card 12 centimetres by 8 centimetres with the instruction that she had to draw two intersecting straight lines across the card from adjacent corners. The point of intersection had to be such that by cutting along two of the lines from the intersection point to the edge of the card, a piece of card with an area equal to any multiple (from 1 to 6) of 8 square centimetres could be produced.

How far from the nearer shorter side was the point of intersection of the two lines?



One response to “Enigma 1569: Cardiology

  1. jimrandell 21 February 2012 at 4:44 pm

    The following Python program runs in 71ms.

    # let's assume the rectangle is:
    #    m   x2
    #   +----------+
    # l |\ B/      |
    #   |A\/       |
    #   | /\ D     |
    #   |/ C\      |
    #   +----------+
    #        x1
    # let's assume we have line from the TL corner to the bottom side
    # likewise a line from the BL to the top side
    # divides the rectangle into triangles A, B, C and another piece D
    from fractions import Fraction
    from enigma import printf
    # solve for an l x m rectangle
    def solve(l, m):
      # steps along the x-axis that make triangles A+C and A+B that are multiples of 8
      i = Fraction(16, l)
      # x1 ranges along the bottom
      x1 = i
      while not(x1 > m):
        # the area of the triangle composed of A+C is (l*x1)/2
        AC = Fraction(l * x1, 2)
        # x2 ranges along the top (for uniqueness assume x1 < x2)
        x2 = x1
        while not(x2 > m):
          # the area of the triangle A+B = (l*x2)/2
          AB = Fraction(l * x2, 2)
          # x is where the lines cross (distance along x-axis)
          x = Fraction(x1 * x2, x1 + x2)
          # and the triangle A has area (l*x)/2
          A = Fraction(l * x, 2)
          # compute the areas of all the pieces
          B = AB - A
          C = AC - A
          D = (l * m) - (A + B + C)
          # we need A, B, C, D, A+B, A+C, B+D, C+D to include
          # the multiples of 8 from 1*8 to 6*8
          s = set(a // 8 for a in (A, B, C, D, A+B, A+C, B+D, C+D) if a % 8 == 0)
          if set((1, 2, 3, 4, 5, 6)).issubset(s):
            # distance from the shortest side to (x, y)
            d = x if l < m else Fraction(l * x, x2)
            printf("dist={d} (x1={x1} x2={x2} A={A} B={B} C={C} D={D}) [{l}x{m}]")
          x2 += i
        x1 += i
    # try it as an 8x12 rectangle
    solve(8, 12)
    # and a 12x8 rectangle
    solve(12, 8)

    Solution: 4 centimetres.

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: