fork download
  1. const tomarCaminoX = (x1,y1,x2,y2) => {
  2. const ejeX = Math.abs(x2-x1);//Math.abs(x2-x1);
  3. const ejeY = Math.abs(y2-y1) ; //Math.abs(y2-y1);
  4. if(ejeX > ejeY) return true;
  5. return false;
  6. }
  7. const cantidadSaltosParaGepo = (x1,y1,x2,y2) => {
  8. let contadorpasos = 0;
  9. while(x1<x2 && y1<y2){
  10. const tomarEjex = tomarCaminoX(x1,y1,x2,y2);
  11. if(tomarEjex === true){
  12. x1 =x1+2;
  13. y1 = y1+1;
  14. }else{
  15. x1 = x1+1;
  16. y1 = y1+2;
  17. }
  18. contadorpasos++;
  19. if(x1 === x2 && y1 === y2){
  20. break;
  21. }
  22. }
  23. if(x1 === x2 && y1 === y2){
  24. return contadorpasos.toString();
  25. }else{
  26. return "IMPOSIBLE";
  27. }
  28. }
  29.  
  30. console.log('cantidadPasos: ',cantidadSaltosParaGepo(1, 1, 2, 1)); // 1
Success #stdin #stdout 0.02s 16804KB
stdin
Standard input is empty
stdout
cantidadPasos:  IMPOSIBLE