Skip to content

Instantly share code, notes, and snippets.

@thehadeeryounis
Last active December 17, 2019 14:06
Show Gist options
  • Save thehadeeryounis/dd6b1081598e7d2650141e3124de51e2 to your computer and use it in GitHub Desktop.
Save thehadeeryounis/dd6b1081598e7d2650141e3124de51e2 to your computer and use it in GitHub Desktop.
var modules = [103450,
107815,
53774,
124794,
90372,
98169,
106910,
50087,
104958,
71936,
118379,
122284,
55871,
91714,
120685,
117684,
146047,
60332,
72034,
127689,
117575,
101714,
121018,
86073,
73764,
100533,
104443,
113037,
79474,
123364,
128367,
63620,
54004,
124093,
133256,
95915,
97442,
64267,
70823,
143108,
86422,
118962,
66129,
69445,
51804,
56436,
117587,
64632,
104564,
67514,
108782,
123991,
110932,
122201,
98816,
126708,
69821,
66902,
96993,
55032,
109143,
67678,
58009,
50232,
69841,
101922,
95832,
122820,
72056,
102557,
68727,
85192,
74694,
142252,
140332,
53783,
123036,
88197,
148727,
138393,
87427,
65693,
88448,
51044,
95470,
97336,
121463,
91997,
149518,
66967,
119301,
112022,
57363,
128247,
107454,
77260,
126346,
97658,
137578,
134743];
calcFuel = (module) => (Math.floor(module/3) - 2) > 0 ? (Math.floor(module/3) - 2) + calcFuel(Math.floor(module/3) - 2) : 0;
var fuelNeededForFuel = modules.reduce((acc, current) => acc + calcFuel(current), 0);
var fuelNeeded = modules.reduce((acc, current) => acc + (Math.floor(current/3) - 2), 0);
console.log(fuelNeeded); // 3216868
console.log(fuelNeededForFuel); //4822435
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment