Advertisement
ErolKZ

Untitled

Jun 16th, 2021
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1.  
  2. function solve(input) {
  3.  
  4. let capacity = Number(input[0]);
  5.  
  6. let countLoaded = 0;
  7.  
  8. let result = 0;
  9.  
  10.  
  11.  
  12.  
  13. for (let i = 1; i < Infinity; i++) {
  14.  
  15. if (capacity >= input[i]) {
  16.  
  17. countLoaded += 1;
  18. result = countLoaded / 3;
  19.  
  20. }
  21.  
  22. if (input[i] !== 'End') {
  23.  
  24.  
  25.  
  26. if (capacity > 0 && !Number.isInteger(result)) {
  27.  
  28.  
  29.  
  30. capacity = capacity - +input[i];
  31.  
  32. } else if (Number.isInteger(result) && capacity > 0 && i > 1) {
  33.  
  34.  
  35. capacity = capacity - (+input[i] + (+input[i] * (10 / 100)));
  36.  
  37.  
  38. }
  39.  
  40. } else if (capacity <= 0) {
  41.  
  42. console.log(`No more space!`)
  43. break;
  44.  
  45. } else {
  46.  
  47. console.log(`Congratulations! All suitcases are loaded!`)
  48. break;
  49. }
  50.  
  51.  
  52.  
  53.  
  54. }
  55.  
  56.  
  57. console.log(`Statistic: ${countLoaded} suitcases loaded.`);
  58.  
  59.  
  60. }
  61.  
  62.  
  63.  
  64. solve([
  65.  
  66. '1200.2',
  67. '260',
  68. '380.5',
  69. '125.6',
  70. '305',
  71. 'End'
  72.  
  73. ]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement