kernelthread.com

Javascript

The Towers of Hanoi as a Javascript program.

<!-- The Towers Of Hanoi --> <!-- Javascript --> <!-- Copyright (C) 1998 Amit Singh. All Rights Reserved --> <!-- http://hanoi.kernelthread.com --> <!-- --> <!-- Tested under Communicator 4.04 / x86-Linux --> <!-- This could be a lot more fancy, and graphical, but --> <!-- a Java(TM) graphical version is already there ... --> <HTML> <HEAD> <TITLE>The Towers Of Hanoi</TITLE> <SCRIPT LANGUAGE="JavaScript"> <!-- var moves = 0; function Hanoi(n) { doHanoi(n, 3, 1, 2); document.write('<BR><HR>', moves, ' moves total'); return true; } function doHanoi(n, to, from, using) { if (n > 0) { doHanoi(n-1, using, from, to); document.write('<BR><B>move </B>', from); document.write('<B> -&gt; </B>', to); moves++; doHanoi(n-1, to, using, from); } return true; } // --> </SCRIPT> </HEAD> <BODY BGCOLOR="#ffffff"> <P> <SCRIPT LANGUAGE="JavaScript"> x = location.search.valueOf('N'); y = x.substr(3); document.write('<P><H1>The Towers Of Hanoi (JavaScript version)</H1><HR>'); document.write(y, ' disks<BR>'); Hanoi(y); </SCRIPT> </SCRIPT> </BODY> </HTML>

Download

hanoi.js