-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay11.jl
30 lines (26 loc) · 909 Bytes
/
Day11.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# did have some 'inspiration' for the solution here
f = "/home/er19801/julia_code/Advent-of-code-24/Datafiles/Day11Data.txt"
data = parse.(Int,split(readlines(f)[1]," "))::Vector{Int64}
function stone_count(value, number, mem=Dict())
if number == 0
return 1
end
if !((value, number) in keys(mem))
mem[(value, number)] = if value == 0
stone_count(1, number - 1, mem)
elseif iseven(ndigits(value))
n = 10^(ndigits(value) >> 1)
first = value ÷ n
tail = value % n
stone_count(first, number - 1, mem) + stone_count(tail, number - 1, mem)
else
stone_count(value*2024, number - 1, mem)
end
end
return mem[(value, number)]
end
ans1 = sum(stone_count.(data,25))
println("part 1 answer = ",ans1)
#end of part 1
ans2 = sum(stone_count.(data,75))
println("part 2 answer = ",ans2)