@@ -115,8 +115,6 @@ func inBoundary(p Point, m map[Point]bool) bool {
115115 return true
116116 }
117117
118- // shoot north
119-
120118 if val , ok := memo [p ]; ok {
121119 return val
122120 }
@@ -132,7 +130,8 @@ func inBoundary(p Point, m map[Point]bool) bool {
132130 for i := 0 ; i < WINDOW ; i ++ {
133131 newPoint := Point {row : start , col : p .col }
134132 encountered = append (encountered , newPoint )
135- if m [newPoint ] {
133+ lookAhead := Point {row : start - 1 , col : p .col }
134+ if m [newPoint ] && ! m [lookAhead ] {
136135 intersectsNorth ++
137136 }
138137 start --
@@ -149,46 +148,8 @@ func inBoundary(p Point, m map[Point]bool) bool {
149148 for _ , enc := range encountered {
150149 memo [enc ] = true
151150 }
151+ encountered = nil
152152 return true
153-
154- start = p .row
155- intersectsSouth := 0
156- for i := 0 ; i < WINDOW ; i ++ {
157- newPoint := Point {row : start , col : p .col }
158- if m [newPoint ] {
159- intersectsSouth ++
160- }
161- start ++
162- }
163- if intersectsSouth == 0 {
164- return false
165- }
166-
167- start = p .col
168- intersectsEast := 0
169-
170- for i := 0 ; i < WINDOW ; i ++ {
171- newPoint := Point {row : p .row , col : start }
172- if m [newPoint ] {
173- intersectsEast ++
174- }
175- start ++
176- }
177- if intersectsEast == 0 {
178- return false
179- }
180-
181- start = p .col
182- intersectsWest := 0
183-
184- for i := 0 ; i < WINDOW ; i ++ {
185- newPoint := Point {row : p .row , col : start }
186- if m [newPoint ] {
187- intersectsWest ++
188- }
189- start --
190- }
191- return intersectsNorth % 2 == 1 || intersectsSouth % 2 == 1 || intersectsWest % 2 == 1 || intersectsEast % 2 == 1
192153}
193154
194155type Pair struct {
@@ -209,6 +170,11 @@ func sortedPairs(points []Point) []Pair {
209170 return pairs
210171}
211172
173+ // floodFill the entire rectangle so it's easier to do a 'contain' check
174+ func floodFill (ps []Point ) map [Point ]bool {
175+ return nil
176+ }
177+
212178func solve2 (points []Point ) int {
213179 // draw a polygon essentially
214180 // then 'solve1' with points that are enclosed within this shape..
@@ -230,17 +196,14 @@ func solve2(points []Point) int {
230196 containsAll := func (p1 , p2 , p3 , p4 Point ) bool {
231197 return inBoundary (p1 , borderMap ) && inBoundary (p2 , borderMap ) && inBoundary (p3 , borderMap ) && inBoundary (p4 , borderMap )
232198 }
233- _ = containsAll
234199
235200 // now we need to select 2 points that do not paint outside this figure
236201
237202 pairs := sortedPairs (points )
238203
239- // find the first valid pair..
240-
241- LENGTH := len (pairs [225330 :])
204+ LENGTH := len (pairs )
242205outer:
243- for i , pair := range pairs [ 225330 :] {
206+ for i , pair := range pairs {
244207 fmt .Printf ("checking pair %v of %v\n " , i , LENGTH )
245208 point := pair .a
246209 other := pair .b
@@ -258,24 +221,8 @@ outer:
258221
259222 var x , y Point
260223
261- if point .row > other .row && point .col < other .col {
262- x = Point {row : other .row , col : point .col }
263- y = Point {row : point .row , col : other .col }
264- }
265-
266- if point .row > other .row && point .col > other .col {
267- x = Point {row : other .row , col : point .col }
268- y = Point {row : point .row , col : other .col }
269- }
270-
271- if point .row < other .row && point .col > other .col {
272- x = Point {row : other .row , col : point .col }
273- y = Point {row : point .row , col : other .col }
274- }
275- if point .row < other .row && point .col < other .col {
276- x = Point {row : other .row , col : point .col }
277- y = Point {row : point .row , col : other .col }
278- }
224+ x = Point {row : other .row , col : point .col }
225+ y = Point {row : point .row , col : other .col }
279226
280227 lines := []Point {point , x , other , y , point }
281228 rect := []Point {}
@@ -289,7 +236,6 @@ outer:
289236 }
290237
291238 a := area (point , other )
292- //fmt.Printf("a=%v for %v %v %v %v\n", a, point, other, x, y)
293239 valid := true
294240 for _ , l := range rect {
295241 if ! inBoundary (l , borderMap ) {
@@ -299,6 +245,7 @@ outer:
299245 }
300246
301247 if valid {
248+ // return the first valid area
302249 return a
303250 }
304251 }
0 commit comments