Tower of Hanoi

Tower of Hanoi

The mission is in Blocked Mode. Access to the solutions is blocked for a day or two (even after you share your own), until we'll have enough solutions for you to check. All users who've solved the mission will get the notifications about their opening.

Tower of Hanoi

There is a legend about a Hindu temple in the Indian city of Benares,
whose priests, the Brahmins, are engaged in moving a tower of 64 gold disks.
The discs lie on three diamond needles, a cubit long and as thick as the body of a bee.
The object is to move the entire tower of discs to another needle, one disk at a time where
no larger disk may rest on a smaller one ever.
And then, according to legend, the world comes to an end when the work is done.

Assuming the priests move 1 checker per second, it'll take 2 ** 64 − 1, which is about 1.84×10 ** 19 seconds
to complete the task. This corresponds to roughly 585 billion years,
about 43 times the estimated age of the universe.

The game was invented by the French mathematician Édouard Lucas in 1883.
It is not clear whether Lucas invented this legend or was merely inspired by it.

The game consists of a board with three pins on it and a number of discs of different diameters,
each having a hole in the middle.
At the start of the game, a cone-shaped tower of a number of discs is placed on the first pin in such a way
that there is always a smaller disk on top of a larger disk, the other two pins stay empty.
The object of the game is now to move the entire tower of discs to the last pin, observing the following 2 rules:

1. Only the top disk of any tower may be moved, one disk at a time.
2. A disk can be moved to any pin, but a larger disk never may rest on a smaller one.

The 3 pins are numbered 1, 2 and 3.
Your task is to write a generator function (named hanoi) that takes the number of disks as input and from where and
to which pin a disk should be moved to move the entire tower from the first pin [1] to the last pin[3]
in as less moves as possible as an output.

Input: The number of discs in play as an integer.
Output: A series tuples, containing two integers indicating from and to which pin a disk shall be moved to complete
the task in a minimum number of moves as a generator object.

example: hanoi(2) generates (0, 1), (0, 2), (1, 2)

Settings
Code:
Other:
Invalid hot key. Each hot key should be unique and valid
Hot keys:
CheckiO Extensions

CheckiO Extensions allow you to use local files to solve missions. More info in a blog post.

In order to install CheckiO client you'll need installed Python (version at least 3.8)

Install CheckiO Client first:

pip3 install checkio_client

Configure your tool

checkio --domain=py config --key=

Sync solutions into your local folder

checkio sync

(in beta testing) Launch local server so your browser can use it and sync solution between local file end extension on the fly. (doesn't work for safari)

checkio serv -d

Alternatevly, you can install Chrome extension or FF addon

checkio install-plugin
checkio install-plugin --ff
checkio install-plugin --chromium

Read more here about other functionality that the checkio client provides. Feel free to submit an issue in case of any difficulties.

Pair Programming (Beta-version)

Welcome to Pair Programming! Engage in real-time collaboration on coding projects by starting a session and sharing the provided unique URL with friends or colleagues. This feature is perfect for joint project development, debugging, or learning new skills together. Simply click 'Start Session' to begin your collaborative coding journey!

Waiting for Pair Programming to start...

You are trying to join a pair programming session that has not started yet.

Please wait for the session creator to join.

Waiting for Pair Programming to reconnect...

It looks like the creator of the pair programming session closed the editor window.

It might happen accidentally, so that you can wait for reconnection.

×
 
 
<< <
> >>
exec show

Whats Next?

Free accounts will see Best CheckiO solutions with some delay.
Best Solutions will be opened in a moment
Become Awesome and Don't wait
The next stage is ""
Will be activated in
View More Solutions Random Review Solutions Go to the next mission