Solution to towers of Hanoi problem