2019 day 01 yay
This commit is contained in:
parent
f6e6bd69c7
commit
6facbd56de
5 changed files with 281 additions and 0 deletions
19
2019/01/part2.js
Normal file
19
2019/01/part2.js
Normal file
|
@ -0,0 +1,19 @@
|
|||
const fs = require('fs');
|
||||
|
||||
let input = fs.readFileSync('input.txt', 'utf-8');
|
||||
let totalFuel = 0;
|
||||
input.split('\n').forEach(line => {
|
||||
let num = parseInt(line);
|
||||
if (!num) {
|
||||
console.log(`num not found in ${line}`);
|
||||
return;
|
||||
}
|
||||
let moduleFuel = num;
|
||||
while (true) {
|
||||
thisFuel = Math.floor(moduleFuel/3)-2;
|
||||
if (thisFuel <= 0) { break }
|
||||
moduleFuel = thisFuel;
|
||||
totalFuel += moduleFuel;
|
||||
}
|
||||
});
|
||||
console.log(totalFuel);
|
Loading…
Add table
Add a link
Reference in a new issue