Skip to content
This repository was archived by the owner on Dec 28, 2024. It is now read-only.

Commit 9637411

Browse files
committed
Add hacky solution day 14 part 2
1 parent e96bdb5 commit 9637411

File tree

2 files changed

+41
-4
lines changed

2 files changed

+41
-4
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ automatically rebuilt and redeployed ever time the `common` module or their own
4141

4242
## Progress
4343
* ⭐ means solved
44-
* 🥸 means solved, but takes over a minute to run
44+
* 🥸 means solved, but takes over a minute to run, or requires some manual tinkering
4545

4646
| Day | Solution | Day | Solution |
4747
|-----|----------|-----|----------|
48-
| 01 | ⭐ ⭐ | 14 | |
48+
| 01 | ⭐ ⭐ | 14 |🥸 |
4949
| 02 | ⭐ ⭐ | 15 | |
5050
| 03 | ⭐ ⭐ | 16 | |
5151
| 04 | ⭐ ⭐ | 17 | |

solutions/day14/main.go

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package main
22

33
import (
4+
"bytes"
45
"fmt"
56
"github.com/terminalnode/adventofcode2024/common"
67
"github.com/terminalnode/adventofcode2024/common/util"
8+
"log"
79
)
810

911
const maxX = 100
@@ -12,7 +14,7 @@ const horizontalLine = maxY / 2
1214
const verticalLine = maxX / 2
1315

1416
func main() {
15-
common.Setup(14, part1, nil)
17+
common.Setup(14, part1, part2)
1618
}
1719

1820
func part1(
@@ -43,6 +45,22 @@ func part1(
4345
return fmt.Sprintf("After 100 seconds, area has a safety factor of %d", q1*q2*q3*q4)
4446
}
4547

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+
4664
func getNewPositions(
4765
robots []robot,
4866
seconds int,
@@ -51,7 +69,26 @@ func getNewPositions(
5169
for i, r := range robots {
5270
move := r.move.Multiply(seconds, seconds)
5371
out[i] = r.init.Add(move.X, move.Y).PositiveModulo(maxX+1, maxY+1)
54-
5572
}
5673
return out
5774
}
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

Comments
 (0)