Solution for day one

This commit is contained in:
Eric Wagoner 2022-12-01 00:21:53 -05:00
parent 9362062718
commit 8764826a99
3 changed files with 2288 additions and 0 deletions

1
.nvmrc Normal file
View File

@ -0,0 +1 @@
14.17.6

32
01/code.js Normal file
View File

@ -0,0 +1,32 @@
const fs = require('fs');
const inputArray = fs.readFileSync('input.txt').toString().split("\n");
// Part One
let caloriesArray = [];
let calories = 0;
for (i in inputArray) {
const value = parseInt(inputArray[i]);
if (value > 0) {
calories += value;
} else {
caloriesArray.push(calories);
calories = 0;
}
}
console.log(Math.max(...caloriesArray));
// Part Two
const first = Math.max(...caloriesArray);
caloriesArray.splice(caloriesArray.indexOf(first), 1);
const second = Math.max(...caloriesArray);
caloriesArray.splice(caloriesArray.indexOf(second), 1);
const third = Math.max(...caloriesArray);
console.log(first + second + third);

2255
01/input.txt Normal file

File diff suppressed because it is too large Load Diff