Last active
July 10, 2023 05:14
-
-
Save nickforce/b6788f336d29d62aee2641f6140bc6e1 to your computer and use it in GitHub Desktop.
day01_adventofcode_2022_part1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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