-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday11.um
47 lines (36 loc) · 858 Bytes
/
day11.um
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
fn numsplit(n: int): (int, int) {
l := 0
for p := n; p > 0; p /= 10 {l++}
if l%2 != 0 { return -1, -1 }
m := trunc(exp(l/2*log(10)))
return n%m, n/m
}
var cash: [75]map[int]int
fn count(n: int, m: int, i: int = 0): int {
if i >= m { return 1 }
if validkey(cash[m-i-1], n) {
return cash[m-i-1][n]
}
r := 0
if n == 0 {
r = count(1, m, i+1)
} else if lo, hi := numsplit(n); lo != -1 {
r = count(lo, m, i+1) + count(hi, m, i+1)
} else {
r = count(n*2024, m, i+1)
}
cash[m-i-1][n] = r
return r
}
fn main() {
input := []int{}
for n := 0; scanf("%lld", &n) == 1 {
input = append(input, n)
}
p1, p2 := 0, 0
for _, n in input {
p1 += count(n, 25)
p2 += count(n, 75)
}
printf("Part 1: %v\nPart 2: %v\n", p1, p2)
}