JSFiddle - React, Tailwind, and code Playground
HTML
What is the Complexity (In Big O)?<br/>
The complexity in Big 0 is O(2^n) and the total number of moves required to solve is 2^n - 1.
<br/><br/>
Should we be concerned with the Elves leaving Middle Earth when the 64 disk solution is physically solved when it takes 1 seconds for each move?
<br> If it takes 1 seconds per each move, solving this for 64 disks would take 1*(2^64 - 1) seconds = 1.8446744^19 years. That means the Eldar is no longer going to prolong the Elves' lives.
<br><br/>
<br> Tower A is Mordor.<br/>
<br> Tower B is Isengard. <br/>
<br> Tower C is Minas Tirith. <br/>
<br><br/>
Number of Disk:
<input type="textbox" id="numberOfDisk"
value="" size="3"/>
<br/>
<input type="button" value="Run Middle Earth's Fate"
onClick="solutionTower();" />
<p id='output'></p>
JavaScript
var towerA;
//A=Mordor B= Isengard C= Minas Tirith
var towerB;
var towerC;
var moves = 0;
var towerString = '';
var output = '';
var Node = function(content) {
this.next = null;
this.previous = null;
this.content = content;
}
var Queue = function() {
this.front = null;
this.back = null;
this.push = function(content) {
if (this.front == null) {
this.front = new Node(content);
this.back = this.front;
return this;
}
var addedNode = new Node(content);
addedNode.previous = this.back;
this.back.next = addedNode;
this.back = addedNode;
return this;
}
//declare variables
this.removeFront = function() {
if (this.front == null) {
return null;
}
var contentRemoved = this.front.content;
if(this.back == this.front){
this.front = null;
this.back = null;
return contentRemoved;
}else{
this.front = this.front.next;
this.front.previous = null;
return contentRemoved;
}
}
this.removeBack = function() {
if (this.front == null) {
return null;
}
var contentRemoved = this.back.content;
if(this.back == this.front){
this.front = null;
this.back = null;
return contentRemoved;
}else{
this.back = this.back.previous;
this.back.next = null;
return contentRemoved;
}
}
this.toString = function() {
var str = "";
var node = this.front;
if (this.front == null){
str = "empty";
}
while (node != null) {
str += node.content + " ";
node = node.next;
}
return str;
}
this.countElements = function() {
var countX = 0;
var node = this.front;
while (node != null) {
node = node.next;
countX= countX+1;
}
return countX;
}
...