Enigmatic Code

Programming Enigma Puzzles

Enigma 1623: Over the edge

From New Scientist #2788, 27th November 2010 [link]

To design a book of road maps the publisher took a huge square map of the total area covered. He then drew some vertical lines right down the map and some horizontal lines right across the map, thus dividing it into between 50 and 150 identical rectangles. Each rectangle was a whole number of inches wide and a whole number of inches deep. He then cut along the lines and used the small rectangles as the pages of a book.

On buying a copy of the book I was disgruntled to find that, more often than not, a route that I wanted was near the edge of a page. In fact, taking “near the edge” to mean “two inches or less from an edge”, over half of each page was near the edge. This would not have been the case for a page which was 1 inch longer in either direction.

What was the size of each page?

[enigma1623]

Advertisements

One response to “Enigma 1623: Over the edge

  1. jimrandell 20 December 2011 at 8:41 pm

    The following Python code runs in 34ms.

    from itertools import count
    from enigma import lcm
    
    def sizes():
      # find n,m
      for s in count(2):
        for n in range(1, int(s/2) + 1):
          m = s - n
    
          # centre of the rectangle must be less than the outside border
          if not(2 * n * m < (n + 4) * (m + 4)): continue
    
          # but not if the rectangle was 1 bigger in either dimension
          if 2 * n * (m + 1) < (n + 4) * (m + 5): continue
          if 2 * (n + 1) * m < (n + 5) * (m + 4): continue
    
          # so now consider pages of size n+4, m+4
          yield (n + 4, m + 4)
    
    def main():
      for (n, m) in sizes():
    
        if n + m > 40: break
    
        # the original square must be a multiple of lcm(n, m)
        s = lcm(n, m)
    
        # and the smallest number of pages will be (s/n) * (s/m)
        p = (s // n) * (s // m)
    
        # but we need between 50 and 150 pages...
        for i in count(1):
          t = p * i * i
          if t < 50: continue
          if t > 150: break
    
          print("original map is {si} square, cut into {t} pages, each page is {n}x{m}".format(si=int(s * i), t=int(t), n=n, m=m))
          return
    
    main()
    

    Solution: Each page is 12″ x 15″.

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: