day18
This commit is contained in:
parent
3cea8acd1f
commit
44b8be5a9e
41
day18/day.go
Normal file
41
day18/day.go
Normal file
@ -0,0 +1,41 @@
|
||||
package day18
|
||||
|
||||
import (
|
||||
"tools"
|
||||
)
|
||||
|
||||
func getGridFromInput(inp string) tools.GridToggle {
|
||||
grid := tools.NewGridToggle()
|
||||
for i, c := range inp {
|
||||
grid.Set(i, 0, c == '^')
|
||||
}
|
||||
return grid
|
||||
}
|
||||
|
||||
func calcTraps(grid tools.GridToggle, cols, rows int) tools.GridToggle {
|
||||
for row := 1; row < rows; row++ {
|
||||
for x := 0; x < cols; x++ {
|
||||
grid.Set(x, row,
|
||||
(grid.State(x-1, row-1) && grid.State(x, row-1) && !grid.State(x+1, row-1)) ||
|
||||
(!grid.State(x-1, row-1) && grid.State(x, row-1) && grid.State(x+1, row-1)) ||
|
||||
(grid.State(x-1, row-1) && !grid.State(x, row-1) && !grid.State(x+1, row-1)) ||
|
||||
(!grid.State(x-1, row-1) && !grid.State(x, row-1) && grid.State(x+1, row-1)))
|
||||
}
|
||||
}
|
||||
|
||||
return grid
|
||||
}
|
||||
|
||||
func Part1(puzzle tools.AoCPuzzle) interface{} {
|
||||
inp := puzzle.GetInputString()
|
||||
width := len(inp)
|
||||
field := calcTraps(getGridFromInput(inp), width, 40)
|
||||
return (field.MaxX+1)*(field.MaxY+1) - field.GetOnCount()
|
||||
}
|
||||
|
||||
func Part2(puzzle tools.AoCPuzzle) interface{} {
|
||||
inp := puzzle.GetInputString()
|
||||
width := len(inp)
|
||||
field := calcTraps(getGridFromInput(inp), width, 400000)
|
||||
return (field.MaxX+1)*(field.MaxY+1) - field.GetOnCount()
|
||||
}
|
||||
1
inputs/18
Normal file
1
inputs/18
Normal file
@ -0,0 +1 @@
|
||||
^.^^^.^..^....^^....^^^^.^^.^...^^.^.^^.^^.^^..^.^...^.^..^.^^.^..^.....^^^.^.^^^..^^...^^^...^...^.
|
||||
1
inputs/18_test
Normal file
1
inputs/18_test
Normal file
@ -0,0 +1 @@
|
||||
.^^.^.^^^^
|
||||
3
main.go
3
main.go
@ -17,6 +17,7 @@ import (
|
||||
"aoc2016/day15"
|
||||
"aoc2016/day16"
|
||||
"aoc2016/day17"
|
||||
"aoc2016/day18"
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
@ -51,7 +52,7 @@ func initDayFunctions() {
|
||||
15: {1: day15.Part1, 2: day15.Part2},
|
||||
16: {1: day16.Part1, 2: day16.Part2},
|
||||
17: {1: day17.Part1, 2: day17.Part2},
|
||||
// 18: {1: day18.Part1, 2: day18.Part2},
|
||||
18: {1: day18.Part1, 2: day18.Part2},
|
||||
// 19: {1: day19.Part1, 2: day19.Part2},
|
||||
// 20: {1: day20.Part1, 2: day20.Part2},
|
||||
// 21: {1: day21.Part1, 2: day21.Part2},
|
||||
|
||||
Loading…
Reference in New Issue
Block a user