Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input) {
- let index = 0;
- let target = Number(input[index]);
- index++;
- let startHeight = target - 30;
- let jumpsCount = 0;
- let fail = 0;
- for (let i = startHeight; i <= target; i += 5){
- for (let j = 1; j <= 3; j++) {
- jumpsCount++;
- let currentAttempt = Number(input[index]);
- index++;
- if (currentAttempt > i) {
- fail = 0;
- break;
- } else {
- fail++;
- }
- if (fail === 3) {
- console.log(`Tihomir failed at ${i}cm after ${jumpsCount} jumps.`);
- return;
- }
- }
- }
- console.log(`Tihomir succeeded, he jumped over ${target}cm after ${jumpsCount} jumps.`);
- }
Advertisement
Add Comment
Please, Sign In to add comment