$mode ascii // The Towers Of Hanoi // A+ Implementation // Copyright (C) 2002 Amit Singh. All Rights Reserved. // http://hanoi.kernelthread.com // // Tested under aplus-fsf-4.18 // http://www.aplusdev.org // // For very obvious reasons, ASCII equivalents to APL graphics have // been used (as enabled by the "$mode ascii" line above). You can // try the following APL sequence to look at the APL<->ASCII mapping // on your implementation: // // _nl{`;`ascii} // move{f; t}: { sys.write{1; f; 1}; sys.write{1; " --> "; 5}; sys.write{1; t; 1}; sys.write{1; "\n"; 1}; } // Recursive // dohanoi{n; f; u; t}: { if (n <= 1) move{f; t} else { dohanoi{n - 1; f; t; u}; move{f; t}; dohanoi{n - 1; u; f; t}; } } // Harness function // hanoi{n}: { if (n < 1) drop "illegal number of disks (must be between 1 and 10)\n" else if (n > 10) drop "illegal number of disks (must be between 1 and 10)\n" else dohanoi{n; '1'; '2'; '3'} }