MartenBG

High Jump

Mar 11th, 2019
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. function solve(input) {
  2. let target = Number(input.shift());
  3. let begin = target - 30;
  4. let jump = Number(input.shift());
  5. let current = 0;
  6. let count = 0;
  7.  
  8. for (let k = begin; k <= target; k += 5) {
  9. current = k;
  10. if (jump > k) {
  11. count++;
  12. jump = Number(input.shift());
  13. } else {
  14. fail = 0;
  15. for (n = 1; n <= 3; n++) {
  16. if (jump <= k) {
  17. fail++;
  18. count++;
  19. jump = Number(input.shift());
  20. } else {
  21. count++;
  22. jump = Number(input.shift());
  23. break;
  24. }
  25. if (fail === 3) {
  26. console.log(`Tihomir failed at ${current}cm after ${count} jumps.`)
  27. return;
  28. }
  29. }
  30. }
  31. }
  32. console.log(`Tihomir succeeded, he jumped over ${current}cm after ${count} jumps.`);
  33. }
  34. //solve([250, 225, 224, 225, 228, 231, 235, 234, 235]);
  35. //solve([251, 205, 212, 213, 228, 229, 230, 235]);
Advertisement
Add Comment
Please, Sign In to add comment