Created
December 5, 2019 07:12
-
-
Save samjaninf/407e798a727dbf49b3a549772ac3a686 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Wrong answers: | |
* 17946289, 24473910, 17946495, 8155726 | |
* | |
* Correct Answer: | |
* 4892166 | |
* node Day1p2.js 0.06s user 0.08s system 95% cpu 0.147 total | |
*/ | |
var modules_mass = Array( | |
128167, | |
65779, | |
88190, | |
144176, | |
109054, | |
70471, | |
113510, | |
81741, | |
65270, | |
111217, | |
51707, | |
81122, | |
142720, | |
65164, | |
85045, | |
85776, | |
51332, | |
110021, | |
99706, | |
50512, | |
95429, | |
149220, | |
102777, | |
93907, | |
61769, | |
66946, | |
121583, | |
132351, | |
53809, | |
73261, | |
122964, | |
120792, | |
73998, | |
79590, | |
140881, | |
53130, | |
82498, | |
72725, | |
127422, | |
143777, | |
55787, | |
95454, | |
88293, | |
107988, | |
145145, | |
59562, | |
142929, | |
132977, | |
88825, | |
104657, | |
70644, | |
124614, | |
66443, | |
117825, | |
97016, | |
79578, | |
136114, | |
64975, | |
113838, | |
63294, | |
58466, | |
76827, | |
56288, | |
126977, | |
63815, | |
129398, | |
123017, | |
118773, | |
144464, | |
60620, | |
79084, | |
94685, | |
70854, | |
148054, | |
134179, | |
113832, | |
113742, | |
115771, | |
115543, | |
73241, | |
62914, | |
146134, | |
128066, | |
52002, | |
132377, | |
100765, | |
105048, | |
59936, | |
131324, | |
137384, | |
139352, | |
127350, | |
116249, | |
79847, | |
53530, | |
99738, | |
61969, | |
118730, | |
121980, | |
72977 | |
); | |
var modules_too = Array(); | |
// var total = 3263354; | |
var mass_reducer = (orig_mass, fuel, fuel_mass_rem) => { | |
if (fuel_mass_rem < 6) { | |
// console.log(orig_mass, fuel, Math.abs(fuel_mass_rem)); | |
// console.log(fuel); | |
// ugh = mass + orig_mass + fuel_mass_rem; | |
// return mass + orig_mass + fuel_mass_rem; | |
return fuel; //+ Math.abs(fuel_mass_rem); | |
} | |
// console.log(orig_mass, fuel, Math.abs(fuel_mass_rem)); | |
fuel_mass_rem = Math.floor(fuel_mass_rem / 3) - 2; | |
fuel += fuel_mass_rem; | |
return mass_reducer(orig_mass, fuel, fuel_mass_rem); | |
}; | |
// const test = [14, 1969, 100756]; | |
modules_mass.forEach(m_mass => { | |
// test.forEach(m_mass => { | |
fuel = Math.floor(m_mass / 3) - 2; | |
// console.log(m_mass, fuel, fuel); | |
modules_too.push(mass_reducer(m_mass, fuel, fuel)); | |
}); | |
// ans = 0; | |
// modules_too.forEach(divd => (ans += divd)); | |
// const red = modules_too => modules_too.reduce((sum, item) => sum + item, 0); | |
// console.log(modules_too); | |
var ans = modules_too.reduce((sum, item) => sum + item, 0); | |
// ans = red; | |
// ans += total; | |
console.log(ans); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment