First of all, what prologue do you use to get these results? It looks like you have a debugger turned on or something like that. I highly recommend SWI-Prolog , which gives the correct results.
As for the name of the disks, yes you can do it. Consider something like this:
move([Disc],X,Y,_) :- write('Move disk '), write(Disc), write(' from '), write(X), write(' to '), write(Y), nl. move([Bottom|Rest],Start,Swap,Goal) :- move(Rest,Start,Swap,Goal), move([Bottom],Start,Goal,_), move(Rest,Swap,Goal,Start).
When you run move([biggest,middle,smallest], left, center, right). , you will get the following results:
Move disk smallest from left to center Move disk middle from left to right Move disk smallest from center to right Move disk biggest from left to right Move disk smallest from center to right Move disk middle from center to left Move disk smallest from right to left
The trick is that this is a bottom-up algorithm. Essentially it comes down to:
- Move everything on top of the bottom drive to swap (which is a recursive step)
- Move the lower drive to the target.
- Move everything else from swap to target
Since it is bottom-up, you must specify a list starting from the bottommost drive.