Merge remote-tracking branch 'origin/master' into master
This commit is contained in:
commit
6aa66b4f6f
21
day18/day.go
21
day18/day.go
@ -4,20 +4,15 @@ import (
|
||||
"tools"
|
||||
)
|
||||
|
||||
type coord struct {
|
||||
x int
|
||||
y int
|
||||
}
|
||||
|
||||
func play(grid tools.ToggleGrid, stuckCorners bool) {
|
||||
neighbours := make(map[coord]int)
|
||||
for thisCoord := range grid.GetOnCoordinates() {
|
||||
func play(grid tools.GridToggle, stuckCorners bool) {
|
||||
neighbours := tools.NewGridInt()
|
||||
for _, thisCoord := range grid.GetCoordinates() {
|
||||
for cx := thisCoord.X - 1; cx <= thisCoord.X+1; cx++ {
|
||||
for cy := thisCoord.Y - 1; cy <= thisCoord.Y+1; cy++ {
|
||||
if cy == thisCoord.Y && cx == thisCoord.X {
|
||||
continue
|
||||
}
|
||||
neighbours[coord{cx, cy}]++
|
||||
neighbours.Add(cx, cy, 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -25,20 +20,20 @@ func play(grid tools.ToggleGrid, stuckCorners bool) {
|
||||
for x := 0; x <= grid.MaxX; x++ {
|
||||
for y := 0; y <= grid.MaxY; y++ {
|
||||
if grid.State(x, y) {
|
||||
if neighbours[coord{x, y}] != 2 && neighbours[coord{x, y}] != 3 {
|
||||
if neighbours.Value(x, y) != 2 && neighbours.Value(x, y) != 3 {
|
||||
if !stuckCorners || !grid.IsCorner(x, y) {
|
||||
grid.Set(x, y, tools.Off)
|
||||
}
|
||||
}
|
||||
} else if neighbours[coord{x, y}] == 3 {
|
||||
} else if neighbours.Value(x, y) == 3 {
|
||||
grid.Set(x, y, tools.On)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func makeGridFromInput(input []string) tools.ToggleGrid {
|
||||
grid := tools.NewToogleGrid()
|
||||
func makeGridFromInput(input []string) tools.GridToggle {
|
||||
grid := tools.NewGridToggle()
|
||||
for y, line := range input {
|
||||
for x, c := range line {
|
||||
if c == '#' {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user