Skip to content

Commit 8129aaa

Browse files
committed
2024.11 Part 1
1 parent 6573162 commit 8129aaa

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

2024/11-pebbles/example.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
125 17

2024/11-pebbles/input.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
5910927 0 1 47 261223 94788 545 7771

2024/11-pebbles/main.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package main
2+
3+
import (
4+
"advent-of-code/util"
5+
"fmt"
6+
"math"
7+
)
8+
9+
func main() {
10+
stones := util.StringToInts(util.ReadFileFromArgs(), " ")
11+
12+
for i := 0; i < 25; i++ {
13+
stones = blink(stones)
14+
fmt.Println(len(stones))
15+
}
16+
17+
fmt.Println(len(stones))
18+
}
19+
20+
func blink(stones []int) []int {
21+
result := make([]int, 0, len(stones))
22+
var l, left, mod int
23+
24+
for i := range stones {
25+
if stones[i] == 0 {
26+
result = append(result, 1)
27+
} else if l = util.IntLength(stones[i]); l%2 == 0 {
28+
mod = int(math.Pow(10, float64(l/2)))
29+
left = int(stones[i] / mod)
30+
result = append(result, left)
31+
result = append(result, stones[i]-left*mod)
32+
} else {
33+
result = append(result, stones[i]*2024)
34+
}
35+
}
36+
37+
return result
38+
}

0 commit comments

Comments
 (0)