Mr_Carter

Advent of Code 2019 Day 1 Part 2

Dec 2nd, 2019
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var inputs = [
  2. 97587,
  3. 100963,
  4. 85693,
  5. 127587,
  6. 147839,
  7. 134075,
  8. 128598,
  9. 91290,
  10. 119100,
  11. 138824,
  12. 56295,
  13. 132118,
  14. 105018,
  15. 143092,
  16. 89032,
  17. 104836,
  18. 138278,
  19. 60416,
  20. 62570,
  21. 142110,
  22. 55179,
  23. 80891,
  24. 99106,
  25. 122863,
  26. 108894,
  27. 112654,
  28. 117175,
  29. 96093,
  30. 76214,
  31. 65412,
  32. 124388,
  33. 66465,
  34. 115850,
  35. 147531,
  36. 87643,
  37. 75882,
  38. 62912,
  39. 76100,
  40. 102120,
  41. 83803,
  42. 139304,
  43. 139325,
  44. 126412,
  45. 145152,
  46. 136247,
  47. 68246,
  48. 130156,
  49. 59097,
  50. 79024,
  51. 62480,
  52. 121847,
  53. 54739,
  54. 118690,
  55. 116247,
  56. 117283,
  57. 144827,
  58. 147562,
  59. 126796,
  60. 148210,
  61. 109099,
  62. 98831,
  63. 59412,
  64. 141077,
  65. 121786,
  66. 142878,
  67. 140144,
  68. 57855,
  69. 59571,
  70. 118451,
  71. 149097,
  72. 145088,
  73. 76882,
  74. 53732,
  75. 70543,
  76. 89874,
  77. 114366,
  78. 115683,
  79. 99139,
  80. 108440,
  81. 76964,
  82. 134451,
  83. 109250,
  84. 66021,
  85. 132683,
  86. 149013,
  87. 122917,
  88. 137810,
  89. 108451,
  90. 109606,
  91. 94396,
  92. 106926,
  93. 100901,
  94. 108587,
  95. 99847,
  96. 64257,
  97. 147162,
  98. 133698,
  99. 140775,
  100. 129466,
  101. 72487]
  102.  
  103. //I dont know if you need to initialize but fuck it im initializing
  104. var totalFuel = 0
  105. var fuelFuel = 0
  106. var bonusFuel = 0
  107.  
  108. //loop through each input mass
  109. for(var i=0; i<inputs.length; i++){
  110.  
  111.   //grab the input
  112.   var mass = inputs[i];
  113.  
  114.   //divide by 3, round down, subtract 2 to get the fuel needed for the metal module
  115.   var moduleFuel = (Math.floor(mass/3)-2);
  116.  
  117.   var bonusFuel = moduleFuel
  118.  
  119.   //then repeat a while loop to add fuel for the fuel (and fuel for that fuel etc.)
  120.   while(bonusFuel > 0){
  121.      
  122.     fuelFuel = (Math.floor(bonusFuel/3)-2);
  123.  
  124.     if(fuelFuel > 0){
  125.       bonusFuel = fuelFuel
  126.  
  127.       moduleFuel+=fuelFuel
  128.     }
  129.     else{
  130.       //wish really hard
  131.       bonusFuel = fuelFuel
  132.     }
  133.   }
  134.  
  135.   //add moduleFuel to totalFuel
  136.   totalFuel+=moduleFuel
  137. }
  138.  
  139. console.log("The fuel for all modules is " + totalFuel)
Add Comment
Please, Sign In to add comment