day 25 puzzle 1

This commit is contained in:
Louis Heredero 2024-12-25 19:14:02 +01:00
parent 9300d786f8
commit 93e365d10b
Signed by: HEL
GPG Key ID: 8D83DE470F8544E7
6 changed files with 102 additions and 0 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 135 KiB

After

Width:  |  Height:  |  Size: 135 KiB

View File

@ -46,3 +46,5 @@
stars: 2
24:
stars: 1
25:
stars: 1

39
res/examples/day25.txt Normal file
View File

@ -0,0 +1,39 @@
#####
.####
.####
.####
.#.#.
.#...
.....
#####
##.##
.#.##
...##
...#.
...#.
.....
.....
#....
#....
#...#
#.#.#
#.###
#####
.....
.....
#.#..
###..
###.#
###.#
#####
.....
.....
.....
#....
#.#..
#.#.#
#####

61
src/day25/puzzle1.typ Normal file
View File

@ -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
)

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

Binary file not shown.