Does anyone know what went wrong in this code. It's not printing anything
function waterPuzz(a,b){
if(b==0)
return a ;
return waterPuzz(b,a%b);
}
function pour(fromJug , toJug,d) {
let from = fromJug ;
let to = 0 ;
let step = 1 ;
while(from != d && to != d){
let temp = Math.min(from,toJug-to);
to += temp;
from -= temp;
step++;
if(from==d || to ==d)
break;
if(from ==0){
from == fromJug;
step++;
}
if(to==toJug){
to= 0 ;
step ++;
}
}
return step;
}
function minimumSteps(m,n,d){
if (m>n){
let t = m ;
m = n ;
n = t ;
}
if(d>n)
return -1;
if((d%waterPuzz(n,m)!=0))
return -1;
return Math.min(pour (n,m,d),
pour(m,n,d));
}
//Driving the code by taking user inputs
let m = prompt("Enter the value of Jug1(m) : ");
let n = prompt("Enter the value of Jug2(n) : ");
let d = prompt("Enter d : ");
alert("Minimum numbers" + "of Steps required" + minimumSteps(m,n,d));
I tried to make an water p开发者_如何学Gouzzle solver. But it's not showing anything
精彩评论