This commit is contained in:
benkyd
2022-12-01 11:12:04 +00:00
parent 6551d2841e
commit 378a972285
2 changed files with 2262 additions and 0 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,19 @@
const fs = require('fs');
let elfIndex = 0;
const calorieAmounts = fs.readFileSync('1.input').toString().split(`\n`).reduce((a, c) => {
if (c == '') {
elfIndex++;
a[elfIndex] = 0;
return a;
}
a[elfIndex] += parseInt(c);
return a;
}, [0]);
const part1 = Math.max(...calorieAmounts);
console.log(`PART 1: ${part1}`);
const sortedCalories = calorieAmounts.sort((a, b) => b - a);
console.log(`PART 2: ${sortedCalories[0] + sortedCalories[1] + sortedCalories[2]}`);