Home More Samples
```
///////////////////////////////////////////////////////////////////////////////
// http://rosettacode.org/wiki/Pascal%27s_triangle/Puzzle
// This puzzle involves a Pascals Triangle, also known as a Pyramid of Numbers.
//
//           [ 151]
//          [  ][  ]
//        [40][  ][  ]
//      [  ][  ][  ][  ]
//    [ X][11][ Y][ 4][ Z]
//
// Each brick of the pyramid is the sum of the two bricks situated below it.
// Of the three missing numbers at the base of the pyramid, the middle one is the
// sum of the other two (that is, Y = X + Z).
//
// Write a program to find a solution to this puzzle.
//
///////////////////////////////////////////////////////////////////////////////
//
// Query:
//
//    all PascalsTriangle(arr,x,y,z)
//
// Solution:
//
// arr = [151,81,70,40,41,29,16,24,17,12,5,11,13,4,8]
// x = 5
// y = 13
// z = 8
// ___ Solution: 1 ___ [00:00:00] __ [Backtracks: 0] ____
//
// Number of solutions: 1   Number of backtracks: 0
// Elapsed time: 00:00:00
//
///////////////////////////////////////////////////////////////////////////////
//
//           [ 151]
//         [ a1][ a2]
//        [40][b1][b2]
//      [c1][c2][c3][c4]
//    [ X][11][ Y][ 4][ Z]

pred PascalsTriangle(arr :: [0..]->L,x::L,y::L,z::L) iff
arr = [
151,
a1, a2,
40, b1, b2,
c1, c2, c3, c4,
x, 11,  y,  4,  z ] &

y = x + z &
151 = a1 + a2  &
a1 = 40 + b1 & a2 = b1 + b2 &
40 = c1+ c2 & b1 = c2 + c3 & b2 = c3 + c4 &
c1 = x + 11 & c2 = 11 + y & c3 = y + 4 & c4 = 4 + z

```