Enigmatic Code

Programming Enigma Puzzles

Enigma 1626: Pascal’s pyramid

From New Scientist #2791, 18th December 2010 [link]

This is Pascal’s pyramid. Every stone has a positive number on it and, apart from the base stones, each stone’s number is the sum of the numbers of the two stones on which it rests. The numbers of the six base stones are all different.

Enigma 1626

What are A, B, C, D, E and F?

[enigma1626]

Advertisements

One response to “Enigma 1626: Pascal’s pyramid

  1. jimrandell 14 December 2011 at 12:17 pm

    The following Python code runs in 29ms.

    # A + B = 7
    # A + 3B + 3C + D = 27
    # A + 5B + 10C + 10D + 5E + F = 93
    # D + 2E + F = 15
    
    from enigma import irange, is_distinct, printf
    
    for A in irange(1, 6):
      B = 7 - A
      for C in irange(1, 11):
        if not is_distinct(C, A, B): continue
        D = 27 - (A + 3 * B + 3 * C)
        if not(D > 0): continue
        if not is_distinct(D, A, B, C): continue
        for F in irange(1, 13 - D):
          if not is_distinct(F, A, B, C, D): continue
          E2 = 15 - (D + F)
          if not(E2 > 0): continue
          if not(E2 % 2 == 0): continue
          E = E2 // 2
          if not is_distinct(E, A, B, C, D, F): continue
          if not(A + 5 * B + 10 * C + 10 * D + 5 * E + F == 93): continue
    
          printf("A={A} B={B} C={C} D={D} E={E} F={F}")
    

    Solution: A=2, B=5, C=3, D=1, E=4, F=6.

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: