Factor code for hanoi towers