JSFiddle - React, Tailwind, and code Playground
by Ryan Brown
HTML
<h1>Module 6</h1>
<form id="form">
<div id="my-div">
Enter number.<br>
<input type="text" id="number"><br>
<input type="button" value="Enter" id="click">
</div>
</form>
<br>
<div id="output"></div>
JavaScript
var number = 0;
//when 'Enter' is clicked call ListOne function
document.getElementById("click").onclick = function() {
number = 0; //reset when new number clicked
number = document.getElementById("number").value;
Calculate(number);
}
function Calculate(number) {
return document.getElementById("output").innerHTML = "With " + number + " disk, it will take " + (Math.pow(2, number) -1) + " moves to solve Tower of Hanoi.";
}
/*
Introduction
Recursion is simply put the ability of a function to recursively call itself. Recursion is quite easy and also quite practical. Just don't forget to put in an exit clause to your recursive functions or you will find yourself staring at a spinning hourglass while the algorithm chews up all your available resources.
Tower of Hanoi
The classic example of a recursive solution to a relatively complex problem is the Tower of Hanoi https://en.wikipedia.org/wiki/Tower_of_Hanoi - which is taught in every Computer Science program and in a lot of programming classes. As you add disks the solution becomes more complex, but it is a simple repetition of moves used in the 3 disk solution.
Assignment
We are not going to solve Tower of Hanoi, you are simply going to write a program to demonstrate computational complexity. Using the wikipedia article I want you to write a computer program that calculates the number of moves necessary to solve Tower of Hanoi given a number of disks. Should we be concerned with concerned with the legend of the world ending when the 64 disk solution is physically solved?)
*/