day 2 puzzle 1
This commit is contained in:
parent
b1a59d3cf5
commit
7a8faae694
BIN
progress.png
BIN
progress.png
Binary file not shown.
Before Width: | Height: | Size: 86 KiB After Width: | Height: | Size: 89 KiB |
@ -1,2 +1,4 @@
|
||||
1:
|
||||
stars: 2
|
||||
stars: 2
|
||||
2:
|
||||
stars: 1
|
6
res/examples/day2.txt
Normal file
6
res/examples/day2.txt
Normal file
@ -0,0 +1,6 @@
|
||||
7 6 4 2 1
|
||||
1 2 7 8 9
|
||||
9 7 6 2 1
|
||||
1 3 2 4 5
|
||||
8 6 4 4 1
|
||||
1 3 6 7 9
|
35
src/day2/puzzle1.typ
Normal file
35
src/day2/puzzle1.typ
Normal 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
0
src/day2/puzzle2.typ
Normal file
BIN
src/main.pdf
BIN
src/main.pdf
Binary file not shown.
Loading…
Reference in New Issue
Block a user