georgiev955

Untitled

Mar 18th, 2023
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(input) {
  2.     let index = 0;
  3.     let target = Number(input[index]);
  4.     index++;
  5.     let startHeight = target - 30;
  6.     let jumpsCount = 0;
  7.     let fail = 0;
  8.  
  9.     for (let i = startHeight; i <= target; i += 5){
  10.         for (let j = 1; j <= 3; j++) {
  11.             jumpsCount++;
  12.             let currentAttempt = Number(input[index]);
  13.             index++;
  14.             if (currentAttempt > i) {
  15.                 fail = 0;
  16.                 break;
  17.             } else {
  18.                 fail++;
  19.             }
  20.             if (fail === 3) {
  21.                 console.log(`Tihomir failed at ${i}cm after ${jumpsCount} jumps.`);
  22.                 return;
  23.             }
  24.         }
  25.     }
  26.     console.log(`Tihomir succeeded, he jumped over ${target}cm after ${jumpsCount} jumps.`);
  27. }
Advertisement
Add Comment
Please, Sign In to add comment