1.1 complete

This commit is contained in:
John Shaver 2022-12-01 09:47:43 -08:00
commit 02e744c3c7
2 changed files with 2280 additions and 0 deletions

31
puzzles/1/index.js Normal file
View File

@ -0,0 +1,31 @@
const fs = require('fs/promises');
const main = async (filePath) => {
const input = await fs.readFile(filePath, 'utf8');
const elves = input.split('\n\n');
console.log("Elves: ", elves.slice(0, 5))
const result = elves.reduce(([highestCal, fatestElf], currentFood, currentElfIndex) => {
const currentCal = sumArray(currentFood.split('\n'));
console.log("Current cal: ", currentCal);
if(currentCal >= highestCal) {
return [currentCal, currentElfIndex];
}
return [highestCal, fatestElf];
}, [0, -1]);
return result;
}
const sumArray = (values) =>
values.reduce((a,b) => parseFloat(a) + parseFloat(b), 0);
main("./input.txt").then(result => {
console.log("Done!");
console.log("Result: ", result);
});

2249
puzzles/1/input.txt Normal file

File diff suppressed because it is too large Load Diff