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.

Examples

towerHanoi(3) ➞ 7

towerHanoi(5) ➞ 31

towerHanoi(0) ➞ 0
2 Likes

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:

5 Likes

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.

7 Likes

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

2 Likes

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:

4 Likes

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