-
Notifications
You must be signed in to change notification settings - Fork 0
/
day01.js
114 lines (112 loc) · 1.3 KB
/
day01.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
const moduleMasses = [
54032,
64433,
71758,
133884,
76994,
99596,
90491,
89188,
142280,
127352,
62127,
79849,
96049,
56527,
148029,
81386,
149827,
105377,
91970,
98708,
88611,
99785,
99229,
88460,
80396,
70097,
91784,
81733,
75671,
106787,
77196,
132234,
98698,
115243,
119574,
142851,
58964,
137814,
127695,
92139,
106277,
51240,
121351,
78316,
129472,
65201,
116068,
72803,
52582,
135433,
87619,
68096,
116952,
106437,
70517,
69840,
89863,
134618,
83823,
113436,
103779,
134819,
107928,
138503,
82509,
90104,
98001,
76202,
136238,
66426,
74030,
55075,
124163,
57133,
79908,
109977,
66903,
125400,
130961,
149293,
99203,
120307,
142403,
50262,
52854,
70851,
142213,
77567,
149144,
144582,
58138,
61765,
116209,
128192,
137436,
101406,
69037,
107389,
112389,
124402
];
const totalFuelRequirement = moduleMasses.reduce(
(acc, mass) => acc + getFuelRequirement(mass),
0
);
function getFuelRequirement(mass) {
const fuelRequirement = Math.floor(mass / 3) - 2;
if (fuelRequirement <= 0) return 0;
const fuelsAdditionalRequirement = getFuelRequirement(fuelRequirement);
return fuelRequirement + fuelsAdditionalRequirement;
}