I should probably check this in at some point huh

This commit is contained in:
Joshua Seigler 2022-12-05 08:42:03 -05:00
commit 23e19496a1
20 changed files with 3507 additions and 0 deletions

9
src/day01/README.md Normal file
View file

@ -0,0 +1,9 @@
# 🎄 Advent of Code 2022 - day 1 🎄
## Info
Task description: [link](https://adventofcode.com/2022/day/1)
## Notes
...

69
src/day01/index.ts Normal file
View file

@ -0,0 +1,69 @@
import run from "aocrunner"
const parseInput = (rawInput: string) => {
const byElf = rawInput.split('\n\n')
return byElf.map(x => x.split('\n').map(x => +x))
}
const part1 = (rawInput: string) => {
const input = parseInput(rawInput)
const totals = input.map(elf => elf.reduce((acc, cur) => acc + cur))
const max = totals.sort((a,b) => b - a)[0]
return max
}
const part2 = (rawInput: string) => {
const input = parseInput(rawInput)
const totals = input.map(elf => elf.reduce((acc, cur) => acc + cur))
const sorted = totals.sort((a,b) => b - a)
return sorted[0] + sorted[1] + sorted[2]
}
run({
part1: {
tests: [
{
input: `1000
2000
3000
4000
5000
6000
7000
8000
9000
10000`,
expected: 24000,
},
],
solution: part1,
},
part2: {
tests: [
{
input: `1000
2000
3000
4000
5000
6000
7000
8000
9000
10000`,
expected: 45000,
},
],
solution: part2,
},
trimTestInputs: true,
onlyTests: false,
})