day 2 puzzle 1

This commit is contained in:
2024-12-02 08:01:48 +01:00
parent b1a59d3cf5
commit 7a8faae694
6 changed files with 44 additions and 1 deletions

35
src/day2/puzzle1.typ Normal file
View File

@ -0,0 +1,35 @@
#import "/src/utils.typ": *
#let solve(input) = {
let safe-cnt = 0
for line in input.split("\n") {
let nums = line.split(" ").map(n => int(n))
let increasing
let safe = true
for i in range(nums.len() - 1) {
let d = nums.at(i + 1) - nums.at(i)
let abs-d = calc.abs(d)
if abs-d < 1 or abs-d > 3 {
safe = false
break
}
if i == 0 {
increasing = d > 0
} else if (d > 0) != increasing {
safe = false
break
}
}
if safe {
safe-cnt += 1
}
}
return safe-cnt
}
#show-puzzle(
2, 1,
solve,
example: 2
)

0
src/day2/puzzle2.typ Normal file
View File

Binary file not shown.