ProjectsAOCBlogAbout

Day 01: Calorie Counting

**
Elves are carrying food and we want to know who is carrying the most calories.
Journal

As this was my first exposure to the whole AOC thing, I didn't really know what to expect or what the format was or if it would be changing from day to day or what.

I solved this one completely in the Chrome dev tools console and didn't save it or anything (this was the general approach for the first few days).

I re-solved it here afterward as a dramatic reenactment.

Relevant Code
export const calculateCalorieCarriers = (loadInput: string) => {
const { loads } = loadInput.split("\n").reduce(
(loadAccum, parcel) => {
if (parcel) {
// Add the calories to the current elf
loadAccum.currentCalorieCount += +parcel;
} else {
// An empty line indicates we're starting a new elf
loadAccum.loads.push(loadAccum.currentCalorieCount);
loadAccum.currentCalorieCount = 0;
}
return loadAccum;
},
{ loads: [] as number[], currentCalorieCount: 0 }
);
// Sort all the elves to figure out who is carrying the most
loads.sort((n1, n2) => n2 - n1);
return loads;
};
Output

Top test elves (0ms):

  1. 24000
  2. 11000
  3. 6000
Total: 41000
Top real elves (1ms):
  1. 71506
  2. 69368
  3. 68729
Total: 209603