@@ -122,8 +122,19 @@ func partTwo(contents []string) {
122
122
123
123
cacheMap := make (map [robotStruct ][2 ]int )
124
124
125
- seconds := 10_000
126
- eightInARowSecond := 0
125
+ seconds := 10_000 // Try 10,000
126
+
127
+ // We'll output each second into a file ans then grep for when we have lots of robots in a line, hopefully this works
128
+ fo , err := os .Create ("output" )
129
+ if err != nil {
130
+ panic (err )
131
+ }
132
+ // close fo on exit and check for its returned error
133
+ defer func () {
134
+ if err := fo .Close (); err != nil {
135
+ panic (err )
136
+ }
137
+ }()
127
138
128
139
for i := 1 ; i <= seconds ; i ++ {
129
140
for j , robot := range robots {
@@ -142,32 +153,14 @@ func partTwo(contents []string) {
142
153
143
154
}
144
155
145
- // Let's see if we have 8 in a line, feels a bit arbitrary but might work?
146
156
grid := buildMap (rows , columns , robots )
147
- for i := 0 ; i < rows ; i ++ {
148
- numInRow := 0
149
- for j := 0 ; j < columns ; j ++ {
150
- if grid [i ][j ] == '0' {
151
- numInRow ++
152
- } else if numInRow > 0 {
153
- break
154
- }
155
-
156
- if numInRow >= 8 {
157
- eightInARowSecond = seconds
158
- }
159
- }
160
-
161
- if eightInARowSecond > 0 {
162
- break
163
- }
164
- }
157
+ outputMap (& grid , fo , i )
165
158
}
166
159
// Not really sure how to do this one... maybe just output
167
160
sharedstruct .PrintOutput (sharedstruct.Output {
168
161
Day : 14 ,
169
162
Part : 2 ,
170
- Value : eightInARowSecond ,
163
+ Value : "Run grep on the output and look for the tree! `grep 00000000000000000000 ./output -C 10`" ,
171
164
})
172
165
}
173
166
@@ -214,6 +207,20 @@ func buildMap(rows int, columns int, robots []robotStruct) [][]byte {
214
207
215
208
}
216
209
210
+ func outputMap (grid * [][]byte , fo * os.File , seconds int ) {
211
+ fo .WriteString ("Seconds: " + strconv .Itoa (seconds ))
212
+ fo .WriteString ("\n " )
213
+
214
+ for _ , line := range * grid {
215
+ // write a chunk
216
+ if _ , err := fo .Write (line ); err != nil {
217
+ panic (err )
218
+ }
219
+
220
+ fo .WriteString ("\n " )
221
+ }
222
+ }
223
+
217
224
func displayMap (rows int , columns int , robots []robotStruct ) {
218
225
grid := buildMap (rows , columns , robots )
219
226
0 commit comments