Skip to content

Commit e896feb

Browse files
committed
fixing examples
1 parent 499727c commit e896feb

File tree

3 files changed

+24
-11
lines changed

3 files changed

+24
-11
lines changed

day15/day15.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ func solvePartX(data DataType, y int) []Range {
4949
}
5050
}
5151

52+
if len(ranges) == 0 {
53+
return []Range{}
54+
}
55+
5256
sort.Slice(ranges, func(i, j int) bool { return ranges[i].Min < ranges[j].Min })
5357

5458
for {
@@ -119,7 +123,7 @@ func solvePart1(data DataType) (rc int) {
119123
}
120124

121125
func solvePart2(data DataType) (rc int) {
122-
const miny, maxy = 0, 4000000
126+
const MinXY, MaxXY = 0, 4000000
123127

124128
lines := make([][2]Point, 0, len(data)*4)
125129
for _, sensor := range data {
@@ -140,7 +144,7 @@ func solvePart2(data DataType) (rc int) {
140144
for _, line2 := range lines {
141145
if line1 != line2 {
142146
if point, isValidPoint := LineIntersection(line1, line2); isValidPoint {
143-
if point.Y >= miny && point.Y <= maxy {
147+
if point.Y >= MinXY && point.Y <= MaxXY {
144148
interestingPoints.Add(point.Y)
145149
}
146150
}
@@ -151,7 +155,9 @@ func solvePart2(data DataType) (rc int) {
151155
for y := range interestingPoints {
152156
ranges := solvePartX(data, y)
153157
if len(ranges) == 2 {
154-
return (ranges[0].Max+1)*maxy + y
158+
if ranges[1].Min-ranges[0].Max == 2 {
159+
return (ranges[0].Max+1)*MaxXY + y
160+
}
155161
}
156162
}
157163

day21/day21.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"fmt"
5+
"math"
56
"regexp"
67
"strings"
78

@@ -100,19 +101,24 @@ func solvePart2(data DataType) (rc int) {
100101
right := rootNode.RightNode().Value()
101102

102103
a := 0
103-
b := MaxInt / 2
104+
b := MaxInt
104105
for {
105106
c := (a + b) / 2
107+
106108
data["humn"] = NewValueNode(c)
107-
left := rootNode.LeftNode().Value()
109+
leftC := rootNode.LeftNode().Value() - right
110+
111+
if leftC == 0 {
112+
return c
113+
}
108114

109-
switch {
110-
case left > right:
115+
data["humn"] = NewValueNode(a)
116+
leftA := rootNode.LeftNode().Value() - right
117+
118+
if math.Copysign(1, leftA) == math.Copysign(1, leftC) {
111119
a = c
112-
case left < right:
120+
} else {
113121
b = c
114-
default:
115-
return c
116122
}
117123
}
118124
}

day25/day25.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ func solvePart1(data DataType) (rc string) {
5555
}
5656

5757
func solvePart2(data DataType) (rc string) {
58-
return "Thank you Eric for another wonderful year of AoC!"
58+
// "Thank you Eric for another wonderful year of AoC!"
59+
return "⭐️⭐️"
5960
}
6061

6162
func main() {

0 commit comments

Comments
 (0)