Two cats and a mouse are at various positions on a line. You will be given their starting positions. Your
task is to determine which cat will reach the mouse first, assuming the mouse doesn't move and the cats
travel at equal speed. If the cats arrive at the same time, the mouse will be allowed to move and it will
escape while they fight.
Answer
task is to determine which cat will reach the mouse first, assuming the mouse doesn't move and the cats
travel at equal speed. If the cats arrive at the same time, the mouse will be allowed to move and it will
escape while they fight.
Answer
if(Math.abs(x - z) < Math.abs(y-z)){
return "Cat A";
}
else if (Math.abs(x - z) > Math.abs(y-z)){
return "Cat B";
}
else{
return "Mouse C";
}
return "Cat A";
}
else if (Math.abs(x - z) > Math.abs(y-z)){
return "Cat B";
}
else{
return "Mouse C";
}