Enigmatic Code

Programming Enigma Puzzles

Enigma 26: Occam’s brick

From New Scientist #1168, 16th August 1979 [link] [link]

Nowadays, William of Occam is not what he was. I found him recently in the toolshed of his garden — he has retired to his native Surrey — gloomily using his still-sharp razor to prepare a whole series of what I call bricks, he called rectangular parallelpipeds, and you probably call cuboids, each an exact number of centimetres each way. These he would first paint all over with purple paint and then chop up into 1 cu. cm cubes. Finally, with each brick, he put the cubelets with one or more painted faces into one pile and the other cubelets into another, and counted the two piles. He was hoping, he explained, to make a brick which, when painted and cut up, would yield an equal number in each of the two piles. He also wanted the dimensions of the brick to be coprime in pairs. (That is, if the brick is a × b × c centimetres, a and b having no common factor; nor have a and c; nor b and c.)

I went away, leaving William sawing away regardless. And now I ask you, what are the dimensions of the brick of smallest volume which will meet the old man’s requirements?

[enigma26]

One response to “Enigma 26: Occam’s brick

  1. Jim Randell 28 December 2012 at 10:04 am

    The following Python program runs in 124ms.

    from enigma import (irange, inf, gcd, printf)
    
    # the cubes in the middle of a cubiod are not painted:
    # there are: (a - 2)(b - 2)(c - 2) of them
    # the rest are painted on at least one face
    
    # so we need: 2 < a < b < c, where a, b, c are pairwise co-prime
    # and abc = 2(a - 2)(b - 2)(c - 2)
    
    m = None
    for c in irange(5, inf):
      if m and 12 * c > m[0]: break
      for a in irange(3, c - 1):
        for b in irange(a + 1, c - 1):
          v = a * b * c
          if v != 2 * (a - 2) * (b - 2) * (c - 2): continue
          if not (gcd(a, b) == gcd(a, c) == gcd(b, c) == 1): continue
          if m is None or v < m[0]: m = (v, (a, b, c))
          printf("[v={v} {a}x{b}x{c}]")
    
    printf("min vol = {m[0]}, dimensions = {m[1]}")
    

    Solution: The smallest volume brick has dimensions 7 × 9 × 20 cm. It has a volume of 1260 cu. cm.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.