Thursday, December 15, 2011

Towers of Hanoi

News says, there are fires in some office tower of Hanoi. Details here.

I hope everyone is ok... I wonder if the news reporter has a computer science background. Why not simply call it office building?

The Towers of Hanoi is a famous mathematics/computer puzzle that every computer science student should know about.

Start with 3 pegs and a bunch of disks of various size. The goal is to move them from peg 1 to peg 3. The rules are simple: you can only one disk at a time and you cannot put a big disk on top of a small disk.

Now, write a program to solve this.

This can be solved ultra elegantly with recursion (and other methods), and I've seen that in high school.

If you interview an "architect" and he has no clue what it is immediately show him the door.

No comments: