Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started