Partial solution for 10.1. We've got grouping, but still need sorting and some printing cleanup.

This commit is contained in:
Anna Rose Wiggins 2018-12-12 13:18:53 -05:00
parent 06a0886b67
commit e47b6c4a45
No known key found for this signature in database
GPG key ID: 8D9ACA841015C59A
6 changed files with 328 additions and 0 deletions

View file

@ -0,0 +1,46 @@
// 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
}