From 7d03482c4aa413d3b6f42421422f19b2402531db Mon Sep 17 00:00:00 2001 From: Stefan Harmuth Date: Wed, 30 Dec 2020 00:38:15 +0100 Subject: [PATCH 1/2] adapting to IntGrids --- day18/day.go | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/day18/day.go b/day18/day.go index c024ba5..7e5434a 100644 --- a/day18/day.go +++ b/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() { + neighbours := tools.NewIntGrid() + 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,12 +20,12 @@ 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) } } From 2a9e39188556af15b6379671bcd584588c233dd4 Mon Sep 17 00:00:00 2001 From: Stefan Harmuth Date: Wed, 30 Dec 2020 07:35:29 +0100 Subject: [PATCH 2/2] adapt to updated tools module --- day18/day.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/day18/day.go b/day18/day.go index 7e5434a..baba46f 100644 --- a/day18/day.go +++ b/day18/day.go @@ -4,9 +4,9 @@ import ( "tools" ) -func play(grid tools.ToggleGrid, stuckCorners bool) { - neighbours := tools.NewIntGrid() - for thisCoord := range grid.GetCoordinates() { +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 { @@ -32,8 +32,8 @@ func play(grid tools.ToggleGrid, stuckCorners bool) { } } -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 == '#' {