Skip to content

Instantly share code, notes, and snippets.

@nickforce
Last active July 10, 2023 05:14
Show Gist options
  • Select an option

  • Save nickforce/b6788f336d29d62aee2641f6140bc6e1 to your computer and use it in GitHub Desktop.

Select an option

Save nickforce/b6788f336d29d62aee2641f6140bc6e1 to your computer and use it in GitHub Desktop.
day01_adventofcode_2022_part1
import * as fs from 'fs';
const elves = fs.readFileSync("day01.txt", { encoding: "utf-8" })
.replace(/\r/g, "")
.trim()
.split("\n\n"); // split on newline
function findMaxCaroliesElve() {
const calories = elves.map((elf) => {
const calories = elf.split("\n").map(Number);
return calories.reduce((prev, cur) => prev + cur, 0)
});
console.log(Math.max(...calories));
}
findMaxCaroliesElve();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment