Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input){
- let jumpHeightWanted = +input.shift();
- let jumpHeight = +input.shift();
- let firstJump = jumpHeightWanted - 30;
- let numJumps = 0;
- let failJumps = 0;
- while(jumpHeightWanted>=jumpHeight){
- if(firstJump<jumpHeight){
- firstJump += 5;
- failJumps = 0;
- numJumps++;
- }else if(firstJump>=jumpHeight){
- failJumps ++;
- numJumps++;
- if(failJumps / 3 == 1){
- console.log(`Tihomir failed at ${firstJump}cm after ${numJumps} jumps.`)
- return;
- }
- }
- jumpHeight = input.shift();
- }
- if(jumpHeightWanted<jumpHeight){
- numJumps++;
- console.log(`Tihomir succeeded, he jumped over ${jumpHeightWanted}cm after ${numJumps} jumps.`);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement