const tomarCaminoX = (x1,y1,x2,y2) => {
const ejeX = Math.abs(x2-x1);//Math.abs(x2-x1);
const ejeY = Math.abs(y2-y1) ; //Math.abs(y2-y1);
if(ejeX > ejeY) return true;
return false;
}
const cantidadSaltosParaGepo = (x1,y1,x2,y2) => {
let contadorpasos = 0;
while(x1<x2 && y1<y2){
const tomarEjex = tomarCaminoX(x1,y1,x2,y2);
if(tomarEjex === true){
x1 =x1+2;
y1 = y1+1;
}else{
x1 = x1+1;
y1 = y1+2;
}
contadorpasos++;
if(x1 === x2 && y1 === y2){
break;
}
}
if(x1 === x2 && y1 === y2){
return contadorpasos.toString();
}else{
return "IMPOSIBLE";
}
}
console.log('cantidadPasos: ',cantidadSaltosParaGepo(1, 1, 2, 1)); // 1
Y29uc3QgdG9tYXJDYW1pbm9YID0gKHgxLHkxLHgyLHkyKSA9PiB7CiAgICBjb25zdCBlamVYID0gTWF0aC5hYnMoeDIteDEpOy8vTWF0aC5hYnMoeDIteDEpOwogICAgY29uc3QgZWplWSA9IE1hdGguYWJzKHkyLXkxKSA7IC8vTWF0aC5hYnMoeTIteTEpOwogICAgaWYoZWplWCA+IGVqZVkpIHJldHVybiB0cnVlOwogICAgcmV0dXJuIGZhbHNlOwp9CmNvbnN0IGNhbnRpZGFkU2FsdG9zUGFyYUdlcG8gPSAoeDEseTEseDIseTIpID0+IHsKICAgIGxldCBjb250YWRvcnBhc29zID0gMDsKICAgIHdoaWxlKHgxPHgyICYmIHkxPHkyKXsKICAgICAgICBjb25zdCB0b21hckVqZXggPSB0b21hckNhbWlub1goeDEseTEseDIseTIpOwogICAgICAgIGlmKHRvbWFyRWpleCA9PT0gdHJ1ZSl7CiAgICAgICAgICAgIHgxID14MSsyOwogICAgICAgICAgICB5MSA9IHkxKzE7CiAgICAgICAgfWVsc2V7CiAgICAgICAgICAgIHgxID0geDErMTsKICAgICAgICAgICAgeTEgPSB5MSsyOwogICAgICAgIH0KICAgICAgICBjb250YWRvcnBhc29zKys7CiAgICAgICAgaWYoeDEgPT09IHgyICYmIHkxID09PSB5Mil7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgIH0KICAgIH0KICAgIGlmKHgxID09PSB4MiAmJiB5MSA9PT0geTIpewogICAgICAgIHJldHVybiBjb250YWRvcnBhc29zLnRvU3RyaW5nKCk7CiAgICB9ZWxzZXsKICAgICAgICByZXR1cm4gIklNUE9TSUJMRSI7CiAgICB9Cn0KCmNvbnNvbGUubG9nKCdjYW50aWRhZFBhc29zOiAnLGNhbnRpZGFkU2FsdG9zUGFyYUdlcG8oMSwgMSwgMiwgMSkpOyAvLyAx