diff --git a/progress.png b/progress.png index 21aa751..383a139 100644 Binary files a/progress.png and b/progress.png differ diff --git a/progress.yaml b/progress.yaml index 80bd6a7..0fd1852 100644 --- a/progress.yaml +++ b/progress.yaml @@ -3,4 +3,6 @@ 2: stars: 2 3: - stars: 2 \ No newline at end of file + stars: 2 +4: + stars: 1 \ No newline at end of file diff --git a/res/examples/day4.txt b/res/examples/day4.txt new file mode 100644 index 0000000..c41c5ea --- /dev/null +++ b/res/examples/day4.txt @@ -0,0 +1,10 @@ +MMMSXXMASM +MSAMXMSMSA +AMXSXMAAMM +MSAMASMSMX +XMASAMXAMM +XXAMMXXAMA +SMSMSASXSS +SAXAMASAAA +MAMMMXMMMM +MXMXAXMASX \ No newline at end of file diff --git a/src/day4/puzzle1.typ b/src/day4/puzzle1.typ new file mode 100644 index 0000000..d4a44ee --- /dev/null +++ b/src/day4/puzzle1.typ @@ -0,0 +1,57 @@ +#import "/src/utils.typ": * + +#let check-xmas(lines, ox, oy) = { + let w = lines.first().len() + let h = lines.len() + + let total = 0 + for dy in (-1, 0, 1) { + for dx in (-1, 0, 1) { + if dx == 0 and dy == 0 { + continue + } + let buffer = "" + let x = ox + let y = oy + for i in range(4) { + buffer += lines.at(y).at(x) + x += dx + y += dy + if ( + not "XMAS".starts-with(buffer) or + x < 0 or x >= w or + y < 0 or y >= h + ) { + break + } + } + if buffer == "XMAS" { + total += 1 + } + } + } + return total +} + +#let solve(input) = { + let lines = input.split("\n") + let w = lines.first().len() + let h = lines.len() + + let total = 0 + for y in range(h) { + for x in range(h) { + if lines.at(y).at(x) == "X" { + total += check-xmas(lines, x, y) + } + } + } + + return total +} + +#show-puzzle( + 4, 1, + solve, + example: 18 +) \ No newline at end of file diff --git a/src/day4/puzzle2.typ b/src/day4/puzzle2.typ new file mode 100644 index 0000000..e69de29 diff --git a/src/main.pdf b/src/main.pdf index d93f21f..41d6b48 100644 Binary files a/src/main.pdf and b/src/main.pdf differ