Skip to content

Commit

Permalink
Adding advent day 11 code
Browse files Browse the repository at this point in the history
  • Loading branch information
ldemailly committed Dec 11, 2024
1 parent 3d0b0a2 commit c5f6da9
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions examples/advent_2024_day11.gr
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// https://adventofcode.com/2024/day/11

func applyRules(v, depth) {
if depth == 0 {
1
} else if v == 0 {
applyRules(1, depth-1)
} else {
s := str(v)
l := len(s)
depth = depth - 1
if l%2 == 1 {
applyRules(2024*v, depth)
} else {
left := int(s[0:l/2])
right := int(trim_left(s[l/2:l], "0"))
applyRules(left, depth) + applyRules(right, depth)
}
}
}

n :=25
println(applyRules(125,n)+applyRules(17,n))

// Despite auto memoization, this is still too slow even with the new -no-register

// n = 75
// println(applyRules(125,n)+applyRules(17,n))

0 comments on commit c5f6da9

Please sign in to comment.