day 19 puzzle 1

This commit is contained in:
Louis Heredero 2024-12-19 18:26:07 +01:00
parent 4a429bd62b
commit 5921a90c73
Signed by: HEL
GPG Key ID: 8D83DE470F8544E7
6 changed files with 54 additions and 1 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 128 KiB

After

Width:  |  Height:  |  Size: 129 KiB

View File

@ -34,3 +34,5 @@
stars: 1
18:
stars: 2
19:
stars: 1

10
res/examples/day19.txt Normal file
View File

@ -0,0 +1,10 @@
r, wr, b, g, bwu, rb, gb, br
brwrr
bggr
gbbr
rrbgbr
ubwu
bwurrg
brgr
bbrgwb

41
src/day19/puzzle1.typ Normal file
View File

@ -0,0 +1,41 @@
#import "/src/utils.typ": *
#let is-possible(target, towels: none) = {
if towels == none {
panic()
}
for towel in towels {
if towel == target {
return true
}
if target.starts-with(towel) {
if is-possible(target.slice(towel.len()), towels: towels) {
return true
}
}
}
return false
}
#let solve(input) = {
let (towels, targets) = input.split("\n\n")
towels = towels.split(", ")
let is-possible = is-possible.with(towels: towels)
let total = 0
for target in targets.split("\n") {
if is-possible(target) {
total += 1
}
}
return total
}
#show-puzzle(
19, 1,
solve,
example: 6
)

0
src/day19/puzzle2.typ Normal file
View File

Binary file not shown.