File tree Expand file tree Collapse file tree 3 files changed +40
-0
lines changed Expand file tree Collapse file tree 3 files changed +40
-0
lines changed Original file line number Diff line number Diff line change
1
+ 125 17
Original file line number Diff line number Diff line change
1
+ 5910927 0 1 47 261223 94788 545 7771
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments