day 11 puzzle 1

This commit is contained in:
Louis Heredero 2024-12-11 07:43:17 +01:00
parent 8dddcd6224
commit 32fc0862a7
Signed by: HEL
GPG Key ID: 8D83DE470F8544E7
6 changed files with 44 additions and 1 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 120 KiB

After

Width:  |  Height:  |  Size: 121 KiB

View File

@ -18,3 +18,5 @@
stars: 2 stars: 2
10: 10:
stars: 2 stars: 2
11:
stars: 1

1
res/examples/day11.txt Normal file
View File

@ -0,0 +1 @@
125 17

40
src/day11/puzzle1.typ Normal file
View File

@ -0,0 +1,40 @@
#import "/src/utils.typ": *
#let process(rock) = {
if rock == 0 {
return (1,)
}
let rock-str = str(rock)
if calc.rem(rock-str.len(), 2) == 0 {
let hl = calc.div-euclid(rock-str.len(), 2)
return (
int(rock-str.slice(0, hl)),
int(rock-str.slice(hl))
)
}
return (rock * 2024,)
}
#let blink(rocks) = {
let new-rocks = ()
for rock in rocks {
new-rocks += process(rock)
}
return new-rocks
}
#let solve(input) = {
let rocks = input.split(" ").map(int)
for _ in range(25) {
rocks = blink(rocks)
}
return rocks.len()
}
#show-puzzle(
11, 1,
solve,
example: 55312
)

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

Binary file not shown.