# 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.

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

[enigma1626]

### 2 responses 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.

2. geoffrounce 7 December 2017 at 4:25 pm
```% A Solution in MiniZinc
include "globals.mzn";

%  Pascal Triangle                    Solution

%          93                              93
%         Q  R                           48  45
%       27  N  P                       27  21  24
%      K  L  M  15                   15  12   9  15
%    7  G   H  I  J                7   8   4   5   10
%  A   B  C  D   E   F           2   5   3   1   4    6

var 1..10:A;   var 1..10:B;   var 1..10:C;   var 1..10:D;
var 1..10:E;   var 1..10:F;   var 1..25:G;   var 1..25:H;
var 1..25:I;   var 1..25:J;   var 1..25:K;   var 1..25:L;
var 1..25:M;   var 1..25:N;   var 1..25:P;
var 1..50:Q;   var 1..50:R;

constraint all_different ( [A, B, C, D, E, F] );

% Working down from the top of the triangle, row by row
constraint Q  + R == 93;
constraint 27 + N == Q /\ N + P == R;
constraint K + L == 27 /\ L + M == N /\ M + 15 == P;
constraint 7 + G == K /\ G + H == L /\ H + I == M /\ I + J == 15;
constraint A + B == 7 /\ B + C == G /\ C + D == H /\ D + E == I /\ E + F ==J;

solve satisfy;

output [" A, B, C, D , E, F = " ++ show ( [A, B, C, D, E, F]) ]
++ ["\n G, H, I, J = " ++ show ( [G, H, I, J]) ]
++ ["\n K, L, M , N, P, Q, R = " ++ show ( [ K, L, M , N, P, Q, R]) ];

%    A, B, C, D , E, F      G, H, I,  J      K,  L,  M , N, P,  Q,  R
%  =[2, 5, 3, 1,  4, 6]   =[8, 4, 5, 10]   =[15, 12, 9, 21, 24, 48, 45]
% ----------
% Finished in 65msec

```