Παρασκευή, 18 Φεβρουαρίου 2011

Towers of Hanoi on emu8086


The towers of Hanoi can be solved with recursive and no recursive algorithms. In the wiki page I provided you can see both of them. Still, I thought of another no recursive algorithm that solves the puzzle and programmed it on emu8086.






My algorithm still solves the puzzle in the minimum required moves. To use the algorithm you need to remember just one think, left or right (let's call it abc) and has one and only rule: Move the disk that can be moved and wasn't moved in the last round. The disk should be moved according to what abc says, if that's impossible move the disk to the other way. After the move chance the abc. The first value of abc must be left if you have odd number of disks or right if you don't.

I've also made an add-on in the program. I used Visual Basic to create a program that reads whatever the emu8086's program sends to some specific ports. This program just displays the current position and the number of moves made so far.