Scientific Calculator
vasilkadifeli/TowersOfHanoi
Towers Of Hanoi - Problem solved recursively. Three pegs and a large amount of disks.
Tagged:
// Towers Of Hanoi Problem Solved with Recursion
// Three pegs and a large amount of disks.
// call as : var printout = TowersOfHanoi(5);
// then go and look at var printout at the Variables window
var TowersOfHanoi = function (n){
var solution = [];
var a = "";
var move = function(n,Pfrom,Pto,Pusing) {
n > 0 ? (move(n-1,Pfrom,Pusing,Pto);
push(solution,concat("move disc ",string(n)," from ",Pfrom," to ",Pto));
move(n-1,Pusing,Pto,Pfrom);)
: 0 ;
};
move(n,"A","C","B");
solution;
};
0 Comments
Sign in to leave a comment