1.1 complete
This commit is contained in:
commit
02e744c3c7
2 changed files with 2280 additions and 0 deletions
31
puzzles/1/index.js
Normal file
31
puzzles/1/index.js
Normal 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
2249
puzzles/1/input.txt
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue