Question
Question 3 Note: Write all functions in Scala using a strict functional paradigm. 3.a The Towers of Hanoi is an ancient puzzle, consisting of a
Question 3
Note: Write all functions in Scala using a strict functional paradigm. 3.a The Towers of Hanoi is an ancient puzzle, consisting of a collection of rings of di erent sizes, and three posts mounted on a base. At the beginning all the rings are on the left-most post as shown, and the goal is to move them all to the rightmost post, by moving one ring at a time from one post to another. But, at no time may a larger ring be placed on top of a smaller one! For 1 ring, only 1 move is needed. 2 rings would require 3 moves (Top ring to B, bottom ring to C, top ring to C). Your task is to write a recursive function, that calculates the minimum number of moves needed to transfer all the rings from post A to post C. (Hint: Think about how the solution for n -1 relates to the solution for n rings). 3.b Suppose you add another post to the puzzle. Write another recursive function to determine the minimum number of moves needed now
.
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