Enigmatic Code

Programming Enigma Puzzles

Enigma 1758: Path-o-logical

From New Scientist #2926, 20th July 2013 [link]

Our local park is rectangular, with each of its sides a whole number of metres in length, the longer sides exceeding the shorter ones by 25 metres. The boundaries run north-south and east-west. There are two straight paths of equal length. One runs from the gate at the south-west corner of the park to a point on the northern boundary. The second is at right angles to the first and runs from a point on the first path to the gate at the south-east corner of the park. Each path is a whole number of metres long.

How long are the paths?

[enigma1758]

Advertisements

2 responses to “Enigma 1758: Path-o-logical

  1. Jim Randell 17 July 2013 at 6:44 pm

    If we suppose the dimensions of the park are x and y = x + 25 and the paths have length a, as shown in the diagram.

    Enigma 1758

    Then we can see from the similar triangles that:

    cos(θ) = x/a = a/(x + 25)

    hence:

    a² = x(x + 25)

    (You can also see this by moving the triangles to make a square park with sides a).

    And in order for the paths to meet inside the park we require:

    √((x + 25)² – a²) < a
    ⇒ (x + 25)² < 2a² = 2x(x + 25)
    ⇒ 25 < x

    The following simple Python program finds the first integer x that satisfies the conditions. It runs in 31ms.

    from itertools import count
    from enigma import is_square, printf
    
    for x in count(26):
      y = x + 25
      a = is_square(x * y)
      if a is not None:
        printf("paths={a}m [x={x}m, y={y}m]")
        break
    

    Solution: The paths are each 156 metres long.

    • Jim Randell 18 July 2013 at 12:33 pm

      To solve a more general problem where the dimensions of the park are x and x + n you can use an approach suggested by Brian in this post [ http://www.newenigma.com/enigma/view_enigma.php?id=1758#response7871 (registration required) ] by considering the factors of .

      This Python program lets you specify n on the command line (default is 25, as in the original Enigma puzzle), and returns all possible solutions (there may be none, e.g. when n=20, or there may be more than one, e.g. when n=45).

      # to solve: a^2 = x(x + n) [for a, x, n integers]
      # substituting z = x + n/2 we get:
      # a^2 + (n/2)^2 = z^2
      # n^2 = (2z + 2a)(2z - 2a)
      # and 2z and 2a are integers, so their sum and difference is
      # hence they are factors of n^2.
      # 2z - 2a = d1, 2z + 2a = d2, d1 < d2, d1 * d2 = n^2
      
      from enigma import divisor_pairs, printf
      
      import sys
      n = 25 if len(sys.argv) < 2 else int(sys.argv[1])
      
      n2 = n * n
      for (d1, d2) in divisor_pairs(n2):
        (x, r) = divmod(d2 + d1 - 2 * n, 4)
        if not(r == 0 and x > n): continue
        (a, r) = divmod(d2 - d1, 4)
        assert r == 0
        printf("[n={n}] a={a} [x={x} y={y}]", y=x + n)
      

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: