Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions Project Structure/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,54 @@ function diskCreator(number, className){

// for Move A --> B use this: moves.push([A, B])
function hanoi(from, via, to, n) {
if(n==1){
moves.push([from, to])
}
else{
hanoi(from,via,to, n-1)
hanoi(to,from,via,n-1)
moves.push([from, to])
hanoi(via, from, to,n-1)
}
return
}

function exHanoi_1(start, aux, end, n) {
if(n==1){
moves.push([start,aux])
hanoi(aux,start,end,3)
}
else{
exHanoi_1(start,aux,end,n-1)
moves.push([start,aux])
hanoi(end,start,aux,6*n-6)
hanoi(aux,start,end,6*n-3)
}
alert("your function is not complete")
return
}

function exHanoi_2(A, B, C, D, n) {

hanoi(A,D,B,n)
hanoi(C,D,A,n)
hanoi(B,D,C,n)
alert("your function is not complete")
return

}

function exhanoi_3(A, B, C, n) {
if(n==1){
moves.push([A,C])
hanoi(B,A,C,2)
}
else{
exhanoi_3(A,B,C,n-1)
hanoi(C,A,B,3*n-3)
moves.push([A,C])
hanoi(B,A,C,3*n-1)
}
alert("your function is not complete")
return

Expand Down