Question: S&E 310 Write a function in PROLOG (must run with swipl) that prints (via write function) out the moves to solve a Tower of Hanoi

S&E 310

Write a function in PROLOG (must run with swipl) that prints (via write function) out the moves to solve a Tower of Hanoi puzzle of N disks. The signature of a helper function is provided for you. For extra credit, you can return the moves as a list (in order of first to last) instead of printing. The helper function for the extra credit is not provided. For either, you MUST print out or return in exactly the format shown in the following examples:

Examples:

?- tower_of_hanoi(3). move(1,right) move(2,middle) move(1,middle) move(3,right) move(1,left) move(2,right) move(1,right) true . ?- tower_of_hanoi(3, Moves). Moves = [move(1, right), move(2, middle), move(1, middle), move(3, right), move(1, left), move(2, right), move(1, right)]

% tower_of_hanoi/1 - print out the moves to solve a Tower of Hanoi of Number disks
tower_of_hanoi(Number) :- true.
tower_of_hanoi_impl(Number, Source, Destination, Spare) :- true.
% tower_of_hanoi/2 - return a list of the moves to solve a Tower of Hanoi of Number disks
tower_of_hanoi(Number, Result) :- true.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!