There are five blocks numbered from 1 to 5. The blocks are stacked on top of each other in the following sequence from bottom to top: 4, 1, 2, 5, 3. You are allowed to reverse the order of any number of blocks from the top of the stack, for example from the initial state you can obtain the state 4, 1, 3, 5, 2 by reversing the order of the three top most blocks. The goal is to arrange the blocks according to their numbers with the biggest at the bottom (i.e., 5, 4, 3, 2, 1).
The code provided in ProLog will solve this puzzle easily !!