Partial solution for 10.1. We've got grouping, but still need sorting and some printing cleanup.
This commit is contained in:
parent
06a0886b67
commit
e47b6c4a45
6 changed files with 328 additions and 0 deletions
46
2018/internal/day10/grid.go
Normal file
46
2018/internal/day10/grid.go
Normal 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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue