day 1 puzzle 1

This commit is contained in:
2024-12-01 12:50:55 +01:00
commit 34d2054c21
8 changed files with 239 additions and 0 deletions

21
src/day1/puzzle1.typ Normal file
View File

@@ -0,0 +1,21 @@
#import "/src/utils.typ": *
#let solve(input) = {
let lines = input.split("\n")
let (l1, l2) = ((), ())
let reg = regex("^(\d+)\s+(\d+)$")
for line in lines {
let digits = line.match(reg)
l1.push(int(digits.captures.first()))
l2.push(int(digits.captures.last()))
}
let total = l1.sorted().zip(l2.sorted()).map(((a, b)) => calc.abs(a - b)).sum()
return total
}
#show-puzzle(
1,
solve,
example: 11
)