diff --git a/progress.png b/progress.png index 8f702e1..1dc671f 100644 Binary files a/progress.png and b/progress.png differ diff --git a/progress.yaml b/progress.yaml index 94895da..9bda745 100644 --- a/progress.yaml +++ b/progress.yaml @@ -45,4 +45,6 @@ 23: stars: 2 24: + stars: 1 +25: stars: 1 \ No newline at end of file diff --git a/res/examples/day25.txt b/res/examples/day25.txt new file mode 100644 index 0000000..a53fe9b --- /dev/null +++ b/res/examples/day25.txt @@ -0,0 +1,39 @@ +##### +.#### +.#### +.#### +.#.#. +.#... +..... + +##### +##.## +.#.## +...## +...#. +...#. +..... + +..... +#.... +#.... +#...# +#.#.# +#.### +##### + +..... +..... +#.#.. +###.. +###.# +###.# +##### + +..... +..... +..... +#.... +#.#.. +#.#.# +##### \ No newline at end of file diff --git a/src/day25/puzzle1.typ b/src/day25/puzzle1.typ new file mode 100644 index 0000000..b39ddad --- /dev/null +++ b/src/day25/puzzle1.typ @@ -0,0 +1,61 @@ +#import "/src/utils.typ": * + +#let parse-schematic(schematic) = { + let lines = schematic.split("\n") + let is-key = "." in schematic.first() + + let n-cols = lines.first().len() + let n-rows = lines.len() + let heights = () + + for x in range(n-cols) { + let y = if is-key {n-rows - 2} else {1} + let h = 0 + for i in range(n-rows) { + if lines.at(y).at(x) == "." { + break + } + h += 1 + y += if is-key {-1} else {1} + } + heights.push(h) + } + + return (if is-key {"key"} else {"lock"}, heights) +} + +#let fits(lock, key) = { + let tmp = lock.zip(key).map(p => p.sum()) + return calc.max(..tmp) <= 5 +} + +#let solve(input) = { + let schematics = input.split("\n\n") + + let locks = () + let keys = () + for schematic in schematics { + let (type, heights) = parse-schematic(schematic) + if type == "key" { + keys.push(heights) + } else { + locks.push(heights) + } + } + let total = 0 + for key in keys { + for lock in locks { + if fits(lock, key) { + total += 1 + } + } + } + + return total +} + +#show-puzzle( + 25, 1, + solve, + example: 3 +) \ No newline at end of file diff --git a/src/day25/puzzle2.typ b/src/day25/puzzle2.typ new file mode 100644 index 0000000..e69de29 diff --git a/src/main.pdf b/src/main.pdf index 305c2df..92aa22b 100644 Binary files a/src/main.pdf and b/src/main.pdf differ