Four Treesbeginner series
This puzzle requires you to think a little. Thinking is good for you.
Four trees are planted at the corners of a square. They are an oak, an elm, an ash and a fir. I walk around three sides of the square, thus passing all four trees once.
I notice that the oak and ash are not adjacent. I passed the fir before the elm and also before the oak, and I neither started nor finished at the ash.
In what order did I pass the trees?
First, it is necessary to declare sorts, since it is not convenient to regard everything as an integer in this puzzle. Presumably a sort “tree” enumerated with the four names will do. See the guide page on “sorts” if you don’t understand the sort declaration.
Then for the solution we want the solver to print out an order, which may as well be the integers 1 to 4, so we need to declare a function “position” from trees to integers. Then you can write “position(oak)” for the position of the oak tree in the order, for instance.
We adorn the function declaration with the expression “all_different”. This is (naturally) an instruction to the solver that the positions for different trees must all be different. In other words, we don’t want to allow that there may be two trees in the same position.
To say that all the positions are in the range 1…4 we use a variable x: by starting the constraint with ALL x_ we mean that what is true of _x has to be true of every tree. The logical symbol ∀ could be used in place of the word ALL if we wished.
Solver
Auto Parser Results
No errors found.