Coding challenge Tower of Hanoi

By Ahmed Ali

2 min read

Authors

As developers, we spend much time fixing bugs and doing routine work. We often have tricky problems, but problem-solving is a crucial skill for a developer. Therefore in this article, I want to share with you one of the first coding challenges I faced, and give you the challenge to come up with a proper code solution.

Tower of Hanoi

The Tower of Hanoi is also known as the Tower of Brahma or the Lucas tower, as the French mathematician Edouard Lucas introduced it back in 1883. Solving Tower of Hanoi is a well-known coding challenge. You have three pegs with disks of different sizes on one of them; The objective of the puzzle is to move all the disks from the leftmost peg to the rightmost peg.

Game rules

  1. Move only one disk at a time.
  2. A larger disk may not be placed on top of a smaller disk.
  3. All disks, except the one being moved, must be on a peg.

Do you think you can write a piece of code to solve this puzzle?

Using your favorite programming language write a function that takes the number of disks as an input and returns an array of steps needed to solve the puzzle.

I will be sharing my thoughts and solution with you in my next article, till then you can think of a solution that helps solve the Tower of Hanoi.


Share