Daily Challenge #20

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.


towerHanoi(3) ➞ 7

towerHanoi(5) ➞ 31

towerHanoi(0) ➞ 0

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?

This is enough to solve the challenge today :+1:

1 Like

But if you want to extend it that is surely ok with me. :crazy_face:

1 Like

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 :sweat_smile:

1 Like

Maybe I searched for Towers of Hanior’s algorithm a bit in internet :sweat_smile:

So I made that:


Nice work :+1::+1::+1::+1::+1::+1::+1:

1 Like

I asked that because this challenge can be made too with simple math formula without recursion method.


Yes, these blocks are enough to calculate the number of steps. :+1:


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. :grin:


This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.