Peter, Paul, Mary – Lemon Tree

When I was just a lad of ten, my father said to me, “Come here and take a lesson from the lovely lemon tree.” “Don’t put your faith in love, my boy”, my father said to me, “I fear you’ll find that love is like the lovely lemon tree.”

Lemon tree very pretty and the lemon flower is sweet But the fruit of the poor lemon is impossible to eat. Lemon tree very pretty and the lemon flower is sweet But the fruit of the poor lemon is impossible to eat.

One day beneath the lemon tree, my love and I did lie A girl so sweet that when she smiled the stars rose in the sky. We passed that summer lost in love beneath the lemon tree The music of her laughter hid my father’s words from me:

Lemon tree very pretty and the lemon flower is sweet But the fruit of the poor lemon is impossible to eat. Lemon tree very pretty and the lemon flower is sweet But the fruit of the poor lemon is impossible to eat.

One day she left without a word. She took away the sun. And in the dark she left behind, I knew what she had done. She’d left me for another, it’s a common tale but true. A sadder man but wiser now I sing these words to you:

Lemon tree very pretty and the lemon flower is sweet But the fruit of the poor lemon is impossible to eat. Lemon tree very pretty and the lemon flower is sweet But the fruit of the poor lemon is impossible to eat.

 

The inverted pyramid puzzle

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”