parent
9362062718
commit
8764826a99
@ -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); |
File diff suppressed because it is too large
Load Diff
Loading…
Reference in new issue