47 lines
1.0 KiB
Go
47 lines
1.0 KiB
Go
|
// Unused solution: this works fine for the example, but doesn't work at all for the
|
||
|
// real input data.
|
||
|
package day10
|
||
|
|
||
|
import "fmt" // debug
|
||
|
|
||
|
// AnalyzePoints tries to determine whether the data looks sufficiently ordered.
|
||
|
// It returns 'true' if it thinks we've got letters.
|
||
|
func AnalyzePoints(points []*Point) bool {
|
||
|
pointArr := makeBuffer(points)
|
||
|
|
||
|
// count adjacencies
|
||
|
count := 0
|
||
|
|
||
|
for y := 0; y < len(pointArr[0]); y++ {
|
||
|
for x := 0; x < len(pointArr); x++ {
|
||
|
if pointArr[x][y] != '#' {
|
||
|
continue
|
||
|
}
|
||
|
|
||
|
if checkPoint(pointArr, x-1, y) ||
|
||
|
checkPoint(pointArr, x+1, y) ||
|
||
|
checkPoint(pointArr, x, y-1) ||
|
||
|
checkPoint(pointArr, x, y+1) {
|
||
|
count++
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
fmt.Println(float64(count) / float64(len(points))) // debug
|
||
|
return float64(count) >= 0.8*float64(len(points))
|
||
|
}
|
||
|
|
||
|
// Checks the point in the grid. If it is '#' returns true.
|
||
|
func checkPoint(grid [][]byte, x, y int) bool {
|
||
|
if x < 0 || x >= len(grid) ||
|
||
|
y < 0 || y >= len(grid[0]) {
|
||
|
return false
|
||
|
}
|
||
|
|
||
|
if grid[x][y] == '#' {
|
||
|
return true
|
||
|
}
|
||
|
|
||
|
return false
|
||
|
}
|