finished part one of day 1

This commit is contained in:
Robert McGovern 2022-12-04 16:48:15 +00:00
parent 2bbb1225e1
commit 29d7c4260c
3 changed files with 2318 additions and 0 deletions

64
aoc/2022/day1/d1c1.js Normal file
View File

@ -0,0 +1,64 @@
use = "strict";
const fs = require("fs");
const inputText = fs.readFileSync("./input.txt").toString("utf-8");
const splitInputText = inputText.split("\n");
const testData = `1000
2000
3000
4000
5000
6000
7000
8000
9000
10000
`;
const splitTestData = testData.split("\n");
// console.log(splitInputText);
// console.log(splitTestData);
function determineHighestCarriedCalories(input) {
let highestTotalCalories = 0;
let numberOfElves = 1;
let elfNumber = 1;
let currentTotalCalories = 0;
input.forEach((line, curIndex, array) => {
if (line.length !== 0) {
currentElf = numberOfElves;
let num = Number.parseInt(line);
if (Number.isInteger(num)) {
// console.log(
// "current Calories: " + currentTotalCalories + " plus " + num
// );
currentTotalCalories += num;
}
} else {
// console.log(
// `Current elf ${currentElf} has ${currentTotalCalories}`
// );
numberOfElves += 1;
if (currentTotalCalories > highestTotalCalories) {
elfNumber = currentElf;
highestTotalCalories = currentTotalCalories;
}
currentTotalCalories = 0;
}
});
console.log(
`The most Calories carried by is Elf ${elfNumber} with ${highestTotalCalories} total calories`
);
return highestTotalCalories;
}
determineHighestCarriedCalories(splitTestData);
determineHighestCarriedCalories(splitInputText);

2240
aoc/2022/day1/input.txt Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,14 @@
1000
2000
3000
4000
5000
6000
7000
8000
9000
10000