Advertisement
Spocoman

Everest

Feb 20th, 2022 (edited)
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. РЕШЕНИЕ С FOR:
  2.  
  3. function everest(input) {
  4.     let start = 5364;
  5.     let days = 1;
  6.  
  7.     for (let i = 0; i < input.length; i++) {
  8.         let sleep = input[i++];
  9.         if (sleep === "END") {
  10.             break;
  11.         } else if (sleep === "Yes") {
  12.             days++;
  13.             if (days === 6) {
  14.                 break;
  15.             }
  16.         }
  17.         start += Number(input[i]);
  18.         if (start >= 8848) {
  19.             break;
  20.         }
  21.     }
  22.  
  23.     if (start < 8848) {
  24.         console.log(`Failed!\n${start}`)
  25.     } else {
  26.         console.log(`Goal reached for ${days} days!`);
  27.     }
  28. }
  29.  
  30. РЕШЕНИЕ С WHILE, SHIFT() И ТЕРНАРЕН ОПЕРАТОР:
  31.  
  32. function everest(input) {
  33.     let start = 5364;
  34.     let days = 1;
  35.  
  36.     while (days !== 6 && input[0] !== "END" && start < 8848) {
  37.         days += input.shift() === "Yes" ? 1 : 0;
  38.         start += Number(input.shift());
  39.     }
  40.  
  41.     console.log(start < 8848 ? `Failed!\n${start}` : `Goal reached for ${days} days!`);
  42. }
  43.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement