Enigmatic Code

Programming Enigma Puzzles

Enigma 1631: Joe’s Pyramid

From New Scientist #2797, 29th January 2011 [link]

This is Joe’s pyramid. Every stone is marked with a different one or two digit positive number.

Where a stone rests on two others, its number is the sum of the numbers marked on the two stones on which it rests.

What number is X?



One response to “Enigma 1631: Joe’s Pyramid

  1. Jim Randell 13 December 2011 at 10:57 pm

    This Python program runs in 815ms – I can get it down to 280ms by explicitly coding up the sums involved, but this is much neater.

    # the layers are:
    # A B C D E F
    # A+B B+C C+D D+E E+F
    # A+2B+C B+2C+D C+2D+E D+2E+F
    # A+3B+3C+D B+3C+3D+E C+3D+3E+F
    # A+4B+6C+4D+E B+4C+6D+4E+F
    # A+5B+10C+10D+5E+F < 100 => C,D < 8, B,E < 11, A,F < 21
    def squish(l):
      if len(l) < 2: return []
      return [l[0] + l[1]] + squish(l[1:])
    def check(l):
      s = set(l)
      while len(l) > 1:
        l2 = squish(l)
        if max(l2) > 99: return False
        n = len(s)
        if len(s) < n + len(l2): return False
        l = l2
      return True
    for C in range(1, 8):
      for D in range(C + 1, 8):
        for B in set(range(1, 11)).difference((C, D)):
          if not check([B, C, D]): continue
          for E in set(range(1, 11)).difference((C, D, B)):
            if not check([B, C, D, E]): continue
            for A in set(range(1, 21)).difference((C, D, B, E)):
              if not check([A, B, C, D, E]): continue
              for F in set(range(1, 21)).difference((C, D, B, E, A)):
                l = [A, B, C, D, E, F]
                if not check(l): continue
                while len(l) > 0:
                  print(' '.join(map(str, l)))
                  l = squish(l)

    Solution: X = 98.

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: