diff --git a/progress.png b/progress.png index 13cef6b..8036758 100644 Binary files a/progress.png and b/progress.png differ diff --git a/progress.yaml b/progress.yaml index 5fb4a13..ec1ccbb 100644 --- a/progress.yaml +++ b/progress.yaml @@ -35,4 +35,4 @@ 18: stars: 2 19: - stars: 1 \ No newline at end of file + stars: 2 \ No newline at end of file diff --git a/src/day19/puzzle2.typ b/src/day19/puzzle2.typ index e69de29..48dc807 100644 --- a/src/day19/puzzle2.typ +++ b/src/day19/puzzle2.typ @@ -0,0 +1,46 @@ +#import "/src/utils.typ": * + +#let solve(input) = { + let (towels, targets) = input.split("\n\n") + + towels = towels.split(", ") + let by-initial = (:) + for towel in towels { + let initial = towel.first() + if initial not in by-initial { + by-initial.insert(initial, ()) + } + by-initial.at(initial).push(towel) + } + + let count(target) = { + let initial = target.first() + if initial not in by-initial { + return 0 + } + let cnt = 0 + for towel in by-initial.at(initial) { + if towel == target { + cnt += 1 + } else if target.starts-with(towel) { + cnt += count(target.slice(towel.len())) + } + } + + return cnt + } + + let total = 0 + for target in targets.split("\n") { + total += count(target) + } + return total +} + +#show-puzzle( + 19, 2, + solve, + example: 16, + only-example: true +) +#show-result(632423618484345) \ No newline at end of file diff --git a/src/main.pdf b/src/main.pdf index 1dd537f..6b6fc57 100644 Binary files a/src/main.pdf and b/src/main.pdf differ