26 ms·
Presented without comment. Input: move(1,X,Y,_) :- write('Move top disk from '), write(X), write(' to '), write(Y), nl. move(N,X,Y,Z
by holonomically 5y ago
Presented without comment.
Input:
move(1,X,Y,_) :-
write('Move top disk from '),
write(X),
write(' to '),
write(Y),
nl.
move(N,X,Y,Z) :-
N>1,
M is N-1,
move(M,X,Z,Y),
move(1,X,Y,_),
move(M,Z,Y,X).
Output:
- The code starts by writing "Move top disk from X to Y".
- Next, the code writes "N is N-1", which means that it's moving the next disk down.
- The code then moves the first disk up and writes "move(M,X,Z,Y)".
- This means that it's moving M disks down and Z disks up.
- Then it moves 1 disk left and writes "move(M,Z,Y,X).
–
- The code will move the top disk from 1 to 2.
This is a silly project.