Advertisement
Guest User

HighJump

a guest
Feb 7th, 2020
939
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(input) {
  2.     let jumpHeightWanted = +input.shift();
  3.     let jumpHeight = +input.shift();
  4.     let firstJump = jumpHeightWanted - 30;
  5.     let numJumps = 1;
  6.     let failJumps = 0;
  7.     while (true) {
  8.         if (jumpHeight > firstJump) {
  9.             if (firstJump >= jumpHeightWanted) {
  10.                 console.log(`Tihomir succeeded, he jumped over ${jumpHeightWanted}cm after ${numJumps} jumps.`);
  11.                 return;
  12.             }
  13.             firstJump += 5;
  14.             failJumps = 0;
  15.         } else {
  16.             failJumps++;
  17.             if (failJumps == 3) {
  18.                 console.log(`Tihomir failed at ${firstJump}cm after ${numJumps} jumps.`);
  19.                 return;
  20.             }
  21.         }
  22.         jumpHeight = +input.shift();
  23.         numJumps++;
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement