kernelthread.com

ABC

The Towers of Hanoi as an ABC program.

ABC is an interactive programming language and environment for personal computing, originally intended as a good replacement for BASIC. It was designed by first doing a task analysis of the programming task.

Full details of ABC and the implementations, along with many example programs are in the book The ABC Programmer's Handbook by Leo Geurts, Lambert Meertens and Steven Pemberton, published by Prentice-Hall (ISBN 0-13-000027-2).

\ The Towers Of Hanoi \ ABC Implementation \ Copyright (C) 2003 Amit Singh. All Rights Reserved. \ http://hanoi.kernelthread.com \ \ Tested under ABC Release 1.05.02 (central workspace) \ HOW TO HANOI n: PUT {} IN stack PUT n IN stack[1] PUT 1 IN stack[2] PUT 3 IN stack[3] PUT 0 IN stack[4] PUT 4 IN esp WHILE esp > 0: PUT stack[esp] IN processed PUT esp - 1 IN esp PUT stack[esp] IN dto PUT esp - 1 IN esp PUT stack[esp] IN dfrom PUT esp - 1 IN esp PUT stack[esp] IN dn PUT esp - 1 IN esp PUT 6 - dfrom - dto IN dleft IF processed = 0: IF dn = 1: WRITE dfrom, " --> ", dto / IF NOT dn = 1: PUT esp + 1 IN esp PUT dn IN stack[esp] PUT esp + 1 IN esp PUT dfrom IN stack[esp] PUT esp + 1 IN esp PUT dto IN stack[esp] PUT esp + 1 IN esp PUT 1 IN stack[esp] PUT esp + 1 IN esp PUT dn - 1 IN stack[esp] PUT esp + 1 IN esp PUT dfrom IN stack[esp] PUT esp + 1 IN esp PUT dleft IN stack[esp] PUT esp + 1 IN esp PUT 0 IN stack[esp] IF NOT processed = 0: WRITE dfrom, " --> ", dto / PUT esp + 1 IN esp PUT dn - 1 IN stack[esp] PUT esp + 1 IN esp PUT dleft IN stack[esp] PUT esp + 1 IN esp PUT dto IN stack[esp] PUT esp + 1 IN esp PUT 0 IN stack[esp] \ HANOI n runs this for n disks HANOI 3

Download

hanoi.abc