Peter
(Moderator)
October 1, 2019, 5:00am
#1
Towers of Hanoi
There are three towers. Object of the game is to move all the disks over to tower #3 . But you cannot place a larger disk onto a smaller disk.
Create a procedure that takes a number discs
as an argument and returns the minimum amount of steps needed to complete the game.
Examples
towerHanoi(3) ➞ 7
towerHanoi(5) ➞ 31
towerHanoi(0) ➞ 0
2 Likes
yusufcihan
(Yusuf Cihan)
October 1, 2019, 5:56am
#2
Is it required to calculate steps by moving discs with calling the same procedure in that procedure, or will simple math formula be accepted too?
Peter
(Moderator)
October 1, 2019, 5:57am
#3
This is enough to solve the challenge today
1 Like
Peter
(Moderator)
October 1, 2019, 5:57am
#4
But if you want to extend it that is surely ok with me.
1 Like
yusufcihan
(Yusuf Cihan)
October 1, 2019, 5:59am
#5
I thought I can make it with variables by saving discs positions maybe, because it is hard to do that in one return procedure block
1 Like
yusufcihan
(Yusuf Cihan)
October 1, 2019, 6:49am
#6
Maybe I searched for Towers of Hanior’s algorithm a bit in internet
So I made that:
5 Likes
yusufcihan
(Yusuf Cihan)
October 1, 2019, 6:59am
#8
I asked that because this challenge can be made too with simple math formula without recursion method.
7 Likes
Peter
(Moderator)
October 1, 2019, 7:29am
#9
Yes, these blocks are enough to calculate the number of steps.
2 Likes
Italo
(Italo)
October 2, 2019, 7:42pm
#10
That’s exactly what programming should be. in any language, even in blocks.
It’s like in nature, the optimal solution should involve the least amount of energy.
4 Likes
Peter
(Moderator)
Closed
November 1, 2019, 7:53pm
#11
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.