1
1
package main
2
2
3
3
import (
4
+ "bytes"
4
5
"fmt"
5
6
"github.com/terminalnode/adventofcode2024/common"
6
7
"github.com/terminalnode/adventofcode2024/common/util"
8
+ "log"
7
9
)
8
10
9
11
const maxX = 100
@@ -12,7 +14,7 @@ const horizontalLine = maxY / 2
12
14
const verticalLine = maxX / 2
13
15
14
16
func main () {
15
- common .Setup (14 , part1 , nil )
17
+ common .Setup (14 , part1 , part2 )
16
18
}
17
19
18
20
func part1 (
@@ -43,6 +45,22 @@ func part1(
43
45
return fmt .Sprintf ("After 100 seconds, area has a safety factor of %d" , q1 * q2 * q3 * q4 )
44
46
}
45
47
48
+ func part2 (
49
+ input string ,
50
+ ) string {
51
+ robots , err := parseRobots (input )
52
+ if err != nil {
53
+ return fmt .Sprintf ("Failed to parse robots: %v" , err )
54
+ }
55
+
56
+ // It's not going to be be very early, so lets save some time by skipping 5k
57
+ for i := 5000 ; i < 15_000 ; i ++ {
58
+ printPositions (i , getNewPositions (robots , i ))
59
+ }
60
+
61
+ return "kubectl logs -l day=14 -f | tee -a log.txt, then grep for a bunch of # :-)"
62
+ }
63
+
46
64
func getNewPositions (
47
65
robots []robot ,
48
66
seconds int ,
@@ -51,7 +69,26 @@ func getNewPositions(
51
69
for i , r := range robots {
52
70
move := r .move .Multiply (seconds , seconds )
53
71
out [i ] = r .init .Add (move .X , move .Y ).PositiveModulo (maxX + 1 , maxY + 1 )
54
-
55
72
}
56
73
return out
57
74
}
75
+
76
+ func printPositions (
77
+ steps int ,
78
+ positions []util.Coordinate ,
79
+ ) {
80
+ m := make ([][]byte , maxY + 1 )
81
+ for y := range m {
82
+ m [y ] = bytes .Repeat ([]byte {'.' }, maxX + 1 )
83
+ }
84
+
85
+ for _ , p := range positions {
86
+ m [p.Y ][p.X ] = '#'
87
+ }
88
+
89
+ log .Println ("Matrix after step " , steps )
90
+ for _ , r := range m {
91
+ log .Println (string (r ))
92
+ }
93
+ log .Println ("------------------" )
94
+ }
0 commit comments