Compare commits
No commits in common. "0950e76d8dcfb9d41eb3074889af3232365d95d6" and "4a429bd62bbcfad9cbbe11197053643d85b67cc6" have entirely different histories.
0950e76d8d
...
4a429bd62b
BIN
progress.png
BIN
progress.png
Binary file not shown.
Before Width: | Height: | Size: 129 KiB After Width: | Height: | Size: 128 KiB |
@ -33,6 +33,4 @@
|
|||||||
17:
|
17:
|
||||||
stars: 1
|
stars: 1
|
||||||
18:
|
18:
|
||||||
stars: 2
|
|
||||||
19:
|
|
||||||
stars: 2
|
stars: 2
|
@ -1,10 +0,0 @@
|
|||||||
r, wr, b, g, bwu, rb, gb, br
|
|
||||||
|
|
||||||
brwrr
|
|
||||||
bggr
|
|
||||||
gbbr
|
|
||||||
rrbgbr
|
|
||||||
ubwu
|
|
||||||
bwurrg
|
|
||||||
brgr
|
|
||||||
bbrgwb
|
|
@ -1,41 +0,0 @@
|
|||||||
#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
|
|
||||||
)
|
|
@ -1,46 +0,0 @@
|
|||||||
#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)
|
|
BIN
src/main.pdf
BIN
src/main.pdf
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user