diff --git a/05/main.go b/05/main.go index f00d576..51d04fa 100644 --- a/05/main.go +++ b/05/main.go @@ -42,12 +42,15 @@ type point struct { } type grid struct { - m map[point]int + m [][]int } func (g *grid) AddLine(start, end point, includeHorizontal bool) { for _, p := range LineFromPoints(start, end, includeHorizontal) { - g.m[p]++ + if g.m[p.x] == nil { + g.m[p.x] = make([]int, 1000) + } + g.m[p.x][p.y]++ } } @@ -109,7 +112,7 @@ func partOne() { scanner := makeScanner(false) grid := &grid{ - m: map[point]int{}, + m: make([][]int, 1000), } for scanner.Scan() { line := scanner.Text() @@ -118,8 +121,10 @@ func partOne() { } var danger int for i := range grid.m { - if grid.m[i] > 1 { - danger++ + for j := range grid.m[i] { + if grid.m[i][j] > 1 { + danger++ + } } } fmt.Println(danger) @@ -129,7 +134,7 @@ func partTwo() { scanner := makeScanner(false) grid := &grid{ - m: map[point]int{}, + m: make([][]int, 1000), } for scanner.Scan() { line := scanner.Text() @@ -138,8 +143,10 @@ func partTwo() { } var danger int for i := range grid.m { - if grid.m[i] > 1 { - danger++ + for j := range grid.m[i] { + if grid.m[i][j] > 1 { + danger++ + } } } fmt.Println(danger)