day08
This commit is contained in:
parent
3a9c5d69b0
commit
202647d6f0
86
day08/day.go
Normal file
86
day08/day.go
Normal file
@ -0,0 +1,86 @@
|
||||
package day08
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"tools"
|
||||
)
|
||||
|
||||
func shiftRight(display *tools.GridToggle, row, maxCol int) {
|
||||
buf := display.State(maxCol, row)
|
||||
for x := maxCol; x > 0; x-- {
|
||||
display.Set(x, row, display.State(x-1, row))
|
||||
}
|
||||
display.Set(0, row, buf)
|
||||
}
|
||||
|
||||
func shiftDown(display *tools.GridToggle, column, maxRow int) {
|
||||
buf := display.State(column, maxRow)
|
||||
for y := maxRow; y > 0; y-- {
|
||||
display.Set(column, y, display.State(column, y-1))
|
||||
}
|
||||
display.Set(column, 0, buf)
|
||||
}
|
||||
|
||||
func printDisplay(display tools.GridToggle, dimX, dimY int) {
|
||||
for y := 0; y <= dimY; y++ {
|
||||
for x := 0; x <= dimX; x++ {
|
||||
if display.State(x, y) {
|
||||
fmt.Print("#")
|
||||
} else {
|
||||
fmt.Print(" ")
|
||||
}
|
||||
}
|
||||
fmt.Println()
|
||||
}
|
||||
}
|
||||
|
||||
func buildDisplayFromInput(input []string) tools.GridToggle {
|
||||
dims := strings.Split(input[0], ",")
|
||||
dimX, _ := strconv.Atoi(dims[0])
|
||||
dimY, _ := strconv.Atoi(dims[1])
|
||||
dimX--
|
||||
dimY--
|
||||
|
||||
display := tools.NewGridToggle()
|
||||
for _, instruction := range input[1:] {
|
||||
parts := strings.Split(instruction, " ")
|
||||
switch parts[0] {
|
||||
case "rect":
|
||||
rectxy := strings.Split(parts[1], "x")
|
||||
rectx, _ := strconv.Atoi(rectxy[0])
|
||||
recty, _ := strconv.Atoi(rectxy[1])
|
||||
for x := 0; x < rectx; x++ {
|
||||
for y := 0; y < recty; y++ {
|
||||
display.Set(x, y, tools.On)
|
||||
}
|
||||
}
|
||||
case "rotate":
|
||||
which, _ := strconv.Atoi(parts[2][2:])
|
||||
amount, _ := strconv.Atoi(parts[4])
|
||||
switch parts[1] {
|
||||
case "row":
|
||||
for i := 0; i < amount; i++ {
|
||||
shiftRight(&display, which, dimX)
|
||||
}
|
||||
case "column":
|
||||
for i := 0; i < amount; i++ {
|
||||
shiftDown(&display, which, dimY)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return display
|
||||
}
|
||||
|
||||
func Part1(puzzle tools.AoCPuzzle) interface{} {
|
||||
return buildDisplayFromInput(puzzle.GetInputArray()).GetOnCount()
|
||||
}
|
||||
|
||||
func Part2(puzzle tools.AoCPuzzle) interface{} {
|
||||
display := buildDisplayFromInput(puzzle.GetInputArray())
|
||||
printDisplay(display, 49, 5)
|
||||
return 0
|
||||
}
|
||||
154
inputs/8
Normal file
154
inputs/8
Normal file
@ -0,0 +1,154 @@
|
||||
50,6
|
||||
rect 1x1
|
||||
rotate row y=0 by 2
|
||||
rect 1x1
|
||||
rotate row y=0 by 5
|
||||
rect 1x1
|
||||
rotate row y=0 by 3
|
||||
rect 1x1
|
||||
rotate row y=0 by 3
|
||||
rect 2x1
|
||||
rotate row y=0 by 5
|
||||
rect 1x1
|
||||
rotate row y=0 by 5
|
||||
rect 4x1
|
||||
rotate row y=0 by 2
|
||||
rect 1x1
|
||||
rotate row y=0 by 2
|
||||
rect 1x1
|
||||
rotate row y=0 by 5
|
||||
rect 4x1
|
||||
rotate row y=0 by 3
|
||||
rect 2x1
|
||||
rotate row y=0 by 5
|
||||
rect 4x1
|
||||
rotate row y=0 by 2
|
||||
rect 1x2
|
||||
rotate row y=1 by 6
|
||||
rotate row y=0 by 2
|
||||
rect 1x2
|
||||
rotate column x=32 by 1
|
||||
rotate column x=23 by 1
|
||||
rotate column x=13 by 1
|
||||
rotate row y=0 by 6
|
||||
rotate column x=0 by 1
|
||||
rect 5x1
|
||||
rotate row y=0 by 2
|
||||
rotate column x=30 by 1
|
||||
rotate row y=1 by 20
|
||||
rotate row y=0 by 18
|
||||
rotate column x=13 by 1
|
||||
rotate column x=10 by 1
|
||||
rotate column x=7 by 1
|
||||
rotate column x=2 by 1
|
||||
rotate column x=0 by 1
|
||||
rect 17x1
|
||||
rotate column x=16 by 3
|
||||
rotate row y=3 by 7
|
||||
rotate row y=0 by 5
|
||||
rotate column x=2 by 1
|
||||
rotate column x=0 by 1
|
||||
rect 4x1
|
||||
rotate column x=28 by 1
|
||||
rotate row y=1 by 24
|
||||
rotate row y=0 by 21
|
||||
rotate column x=19 by 1
|
||||
rotate column x=17 by 1
|
||||
rotate column x=16 by 1
|
||||
rotate column x=14 by 1
|
||||
rotate column x=12 by 2
|
||||
rotate column x=11 by 1
|
||||
rotate column x=9 by 1
|
||||
rotate column x=8 by 1
|
||||
rotate column x=7 by 1
|
||||
rotate column x=6 by 1
|
||||
rotate column x=4 by 1
|
||||
rotate column x=2 by 1
|
||||
rotate column x=0 by 1
|
||||
rect 20x1
|
||||
rotate column x=47 by 1
|
||||
rotate column x=40 by 2
|
||||
rotate column x=35 by 2
|
||||
rotate column x=30 by 2
|
||||
rotate column x=10 by 3
|
||||
rotate column x=5 by 3
|
||||
rotate row y=4 by 20
|
||||
rotate row y=3 by 10
|
||||
rotate row y=2 by 20
|
||||
rotate row y=1 by 16
|
||||
rotate row y=0 by 9
|
||||
rotate column x=7 by 2
|
||||
rotate column x=5 by 2
|
||||
rotate column x=3 by 2
|
||||
rotate column x=0 by 2
|
||||
rect 9x2
|
||||
rotate column x=22 by 2
|
||||
rotate row y=3 by 40
|
||||
rotate row y=1 by 20
|
||||
rotate row y=0 by 20
|
||||
rotate column x=18 by 1
|
||||
rotate column x=17 by 2
|
||||
rotate column x=16 by 1
|
||||
rotate column x=15 by 2
|
||||
rotate column x=13 by 1
|
||||
rotate column x=12 by 1
|
||||
rotate column x=11 by 1
|
||||
rotate column x=10 by 1
|
||||
rotate column x=8 by 3
|
||||
rotate column x=7 by 1
|
||||
rotate column x=6 by 1
|
||||
rotate column x=5 by 1
|
||||
rotate column x=3 by 1
|
||||
rotate column x=2 by 1
|
||||
rotate column x=1 by 1
|
||||
rotate column x=0 by 1
|
||||
rect 19x1
|
||||
rotate column x=44 by 2
|
||||
rotate column x=40 by 3
|
||||
rotate column x=29 by 1
|
||||
rotate column x=27 by 2
|
||||
rotate column x=25 by 5
|
||||
rotate column x=24 by 2
|
||||
rotate column x=22 by 2
|
||||
rotate column x=20 by 5
|
||||
rotate column x=14 by 3
|
||||
rotate column x=12 by 2
|
||||
rotate column x=10 by 4
|
||||
rotate column x=9 by 3
|
||||
rotate column x=7 by 3
|
||||
rotate column x=3 by 5
|
||||
rotate column x=2 by 2
|
||||
rotate row y=5 by 10
|
||||
rotate row y=4 by 8
|
||||
rotate row y=3 by 8
|
||||
rotate row y=2 by 48
|
||||
rotate row y=1 by 47
|
||||
rotate row y=0 by 40
|
||||
rotate column x=47 by 5
|
||||
rotate column x=46 by 5
|
||||
rotate column x=45 by 4
|
||||
rotate column x=43 by 2
|
||||
rotate column x=42 by 3
|
||||
rotate column x=41 by 2
|
||||
rotate column x=38 by 5
|
||||
rotate column x=37 by 5
|
||||
rotate column x=36 by 5
|
||||
rotate column x=33 by 1
|
||||
rotate column x=28 by 1
|
||||
rotate column x=27 by 5
|
||||
rotate column x=26 by 5
|
||||
rotate column x=25 by 1
|
||||
rotate column x=23 by 5
|
||||
rotate column x=22 by 1
|
||||
rotate column x=21 by 2
|
||||
rotate column x=18 by 1
|
||||
rotate column x=17 by 3
|
||||
rotate column x=12 by 2
|
||||
rotate column x=11 by 2
|
||||
rotate column x=7 by 5
|
||||
rotate column x=6 by 5
|
||||
rotate column x=5 by 4
|
||||
rotate column x=3 by 5
|
||||
rotate column x=2 by 5
|
||||
rotate column x=1 by 3
|
||||
rotate column x=0 by 4
|
||||
5
inputs/8_test
Normal file
5
inputs/8_test
Normal file
@ -0,0 +1,5 @@
|
||||
7,3
|
||||
rect 3x2
|
||||
rotate column x=1 by 1
|
||||
rotate row y=0 by 4
|
||||
rotate column x=1 by 1
|
||||
3
main.go
3
main.go
@ -8,6 +8,7 @@ import (
|
||||
"aoc2016/day05"
|
||||
"aoc2016/day06"
|
||||
"aoc2016/day07"
|
||||
"aoc2016/day08"
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
@ -32,7 +33,7 @@ func initDayFunctions() {
|
||||
5: {1: day05.Part1, 2: day05.Part2},
|
||||
6: {1: day06.Part1, 2: day06.Part2},
|
||||
7: {1: day07.Part1, 2: day07.Part2},
|
||||
// 8: {1: day08.Part1, 2: day08.Part2},
|
||||
8: {1: day08.Part1, 2: day08.Part2},
|
||||
// 9: {1: day09.Part1, 2: day09.Part2},
|
||||
// 10: {1: day10.Part1, 2: day10.Part2},
|
||||
// 11: {1: day11.Part1, 2: day11.Part2},
|
||||
|
||||
Loading…
Reference in New Issue
Block a user