diff --git a/progress.png b/progress.png index 383a139..c33e7c4 100644 Binary files a/progress.png and b/progress.png differ diff --git a/progress.yaml b/progress.yaml index 0fd1852..8ce05f4 100644 --- a/progress.yaml +++ b/progress.yaml @@ -5,4 +5,4 @@ 3: stars: 2 4: - stars: 1 \ No newline at end of file + stars: 2 \ No newline at end of file diff --git a/src/day4/puzzle1.typ b/src/day4/puzzle1.typ index d4a44ee..eefd500 100644 --- a/src/day4/puzzle1.typ +++ b/src/day4/puzzle1.typ @@ -40,7 +40,7 @@ let total = 0 for y in range(h) { - for x in range(h) { + for x in range(w) { if lines.at(y).at(x) == "X" { total += check-xmas(lines, x, y) } diff --git a/src/day4/puzzle2.typ b/src/day4/puzzle2.typ index e69de29..8278cec 100644 --- a/src/day4/puzzle2.typ +++ b/src/day4/puzzle2.typ @@ -0,0 +1,33 @@ +#import "/src/utils.typ": * + +#let solve(input) = { + let lines = input.split("\n") + let w = lines.first().len() + let h = lines.len() + + let perms = (("M", "S"), ("S", "M")) + let total = 0 + for y in range(1, h - 1) { + for x in range(1, w - 1) { + if lines.at(y).at(x) == "A" { + let tl = lines.at(y - 1).at(x - 1) + let tr = lines.at(y - 1).at(x + 1) + let bl = lines.at(y + 1).at(x - 1) + let br = lines.at(y + 1).at(x + 1) + let tlbr = (tl, br) + let bltr = (bl, tr) + if tlbr in perms and bltr in perms { + total += 1 + } + } + } + } + + return total +} + +#show-puzzle( + 4, 2, + solve, + example: 9 +) \ No newline at end of file diff --git a/src/main.pdf b/src/main.pdf index 41d6b48..8acfd2e 100644 Binary files a/src/main.pdf and b/src/main.pdf differ