The other day, I was talking to a friend of mine about the Z3 theorem solver and he mentioned the inverted Pyramid puzzle. I told him: “I think this can be solved with Z3” and hence this blog post.
So what’s the inverted pyramid puzzle?
Imagine the following pyramid with 4 rows:
10 9 8 7 6 5 4 3 2 1
The numbers in that triangle are just placeholders for the sake of explanation.
The goal of the puzzle is to find the right order for those numbers in the triangle in such a way that:
For the 4th row, we must have whatever is at the position denoted with [number]
subtracted from its neighbor equals the value of the next row’s value beneath the top 2 numbers (note: we take the absolute value of the subtraction). So:
|[10] - [9]| == [6] |[9] - [8] | == [5] |[8] - [7] | == [4]
And for the 3rd row, we must have:
|[6] - [5]| == [3] |[5] - [4]| == [2]
And for the 2nd row, we must have:
|[3] - [2]| == [1]
Of course, we stop at the first row.
For now, here’s a solution for the inverted pyramid with 4 rows:
8 10 3 9 2 7 6 5 1 4
The numbers configuration from above satisfies the conditions explained above.
Please note that the only numbers accepted in the pyramid are [1..Sigma(rows)
]. Sigma denotes the sum of the arithmetic series going from 1 to rows
. Continue reading “The inverted pyramid puzzle”