Answered step by step
Verified Expert Solution
Link Copied!

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Modeling And Design

Authors: Toby J. Teorey, Sam S. Lightstone, Tom Nadeau, H.V. Jagadish

5th Edition

0123820200, 978-0123820204

More Books

Students also viewed these Databases questions

Question

6. Explain how to train managers to coach employees.

Answered: 1 week ago