diff --git a/progress.png b/progress.png index 77276cf..7dfab21 100644 Binary files a/progress.png and b/progress.png differ diff --git a/progress.yaml b/progress.yaml index 0f03e03..5f75258 100644 --- a/progress.yaml +++ b/progress.yaml @@ -1,2 +1,4 @@ 1: - stars: 2 \ No newline at end of file + stars: 2 +2: + stars: 1 \ No newline at end of file diff --git a/res/examples/day2.txt b/res/examples/day2.txt new file mode 100644 index 0000000..82cd679 --- /dev/null +++ b/res/examples/day2.txt @@ -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 \ No newline at end of file diff --git a/src/day2/puzzle1.typ b/src/day2/puzzle1.typ new file mode 100644 index 0000000..e39fccd --- /dev/null +++ b/src/day2/puzzle1.typ @@ -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 +) \ No newline at end of file diff --git a/src/day2/puzzle2.typ b/src/day2/puzzle2.typ new file mode 100644 index 0000000..e69de29 diff --git a/src/main.pdf b/src/main.pdf index 090bee2..2f67d86 100644 Binary files a/src/main.pdf and b/src/main.pdf differ