day 11 puzzle 2

This commit is contained in:
Louis Heredero 2024-12-11 18:25:31 +01:00
parent 32fc0862a7
commit 2d0001ec12
Signed by: HEL
GPG Key ID: 8D83DE470F8544E7
4 changed files with 37 additions and 1 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 121 KiB

After

Width:  |  Height:  |  Size: 121 KiB

View File

@ -19,4 +19,4 @@
10:
stars: 2
11:
stars: 1
stars: 2

View File

@ -0,0 +1,36 @@
#import "/src/utils.typ": *
#let process(rock, depth) = {
if depth == 0 {
return 1
}
if rock == 0 {
return process(1, depth - 1)
}
let rock-str = str(rock)
if calc.rem(rock-str.len(), 2) == 0 {
let hl = calc.div-euclid(rock-str.len(), 2)
let a = int(rock-str.slice(0, hl))
let b = int(rock-str.slice(hl))
return process(a, depth - 1) + process(b, depth - 1)
}
return process(rock * 2024, depth - 1)
}
#let solve(input) = {
let rocks = input.split(" ").map(int)
let total = 0
for rock in rocks {
total += process(rock, 75)
}
return total
}
#show-puzzle(
11, 2,
solve,
only-example: true
)
// Too long to recompile everytime
#show-result(228651922369703)

Binary file not shown.