Skip to content

Commit 6866430

Browse files
authored
rolfschmidt, add 2024 day 11 (#72)
* Add 2024 day 11 * add output * tidy
1 parent 8135447 commit 6866430

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

2024/11/rolfschmidt.v

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import arrays
2+
import os
3+
4+
fn halve_string(s string) []i64 {
5+
half_len := s.len / 2
6+
return [s[..half_len].i64(), s[half_len..].i64()]
7+
}
8+
9+
fn run(rounds i64) i64 {
10+
mut check := map[i64]i64{}
11+
12+
input := os.read_file('stones.input') or { '' }
13+
for num in input.split(' ') {
14+
check[num.i64()] = 1
15+
}
16+
17+
for _ in 0 .. rounds {
18+
mut cloned := map[i64]i64{}
19+
for key, value in check {
20+
cloned[key] = value
21+
}
22+
23+
for num, count in cloned {
24+
new_values := if num == 0 {
25+
[i64(1)]
26+
} else if num.str().len % 2 == 0 {
27+
halve_string(num.str())
28+
} else {
29+
[num * i64(2024)]
30+
}
31+
32+
check[num] -= count
33+
for new_value in new_values {
34+
if new_value !in check {
35+
check[new_value] = 0
36+
}
37+
check[new_value] += count
38+
}
39+
}
40+
}
41+
42+
return arrays.sum(check.values()) or { 0 }
43+
}
44+
45+
fn main() {
46+
println(run(25))
47+
println(run(75))
48+
}

known/2024/11/rolfschmidt.out

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
55312
2+
65601038650482

0 commit comments

Comments
 (0)