View difference between Paste ID: 637HbHcN and 7NCxHf9C
SHOW: | | - or go back to the newest paste.
1
function solve(input) {
2
  let capacity = +input.shift();
3
4
  let isFull = false;
5
6
  let suitcaseCounter = 0;
7
  let command = input.shift();
8
  while (command !== "End") {
9
    let suitCase = Number(command);
10-
    suitcaseCounter++;
10+
11
    if (suitcaseCounter % 3 == 0) {
12
      suitCase += suitCase * 0.1;
13
    }
14
    capacity -= suitCase;
15
16
    if (capacity <= 0) {
17
      isFull = true;
18
      break;
19
    }
20
	suitcaseCounter++;
21
    command = input.shift();
22
  }
23
  if (command == "End") {
24
    console.log(`Congratulations! All suitcases are loaded!`);
25
  }
26
  if (isFull) {
27
    console.log("No more space!");
28
  }
29
  console.log(`Statistic: ${suitcaseCounter} suitcases loaded.`);
30
}
31-
//solve(["550", "100", "252", " 72", "End"]);
31+
//solve(["550", "100", "252", "72", "End"]);
32-
solve(["700.5", "180", "340.6", " 126", "220"]);
32+
//solve(["700.5", "180", "340.6", "126", "220"]);