This commit is contained in:
Stefan Harmuth 2020-12-22 09:33:45 +01:00
parent c026df5d0a
commit aff0fbe573
4 changed files with 80 additions and 0 deletions

74
day03/day03.go Normal file
View File

@ -0,0 +1,74 @@
package day03
import (
"aoc2015/aoclib"
)
func Part1(puzzle aoclib.Puzzle) interface{} {
x, y := 0, 0
houses := make(map[int]map[int]bool)
for _, c := range puzzle.GetInputArray()[0] {
switch c {
case '^':
x--
case '<':
y--
case '>':
y++
case 'v':
x++
}
if _, ok := houses[x]; !ok {
houses[x] = make(map[int]bool)
}
houses[x][y] = true
}
houseCount := 0
for x := range houses {
houseCount += len(houses[x])
}
return houseCount
}
func Part2(puzzle aoclib.Puzzle) interface{} {
x, y := [2]int{0, 0}, [2]int{0, 0}
turn := 0
houses := make(map[int]map[int]bool)
for _, c := range puzzle.GetInputArray()[0] {
switch c {
case '^':
x[turn]--
case '<':
y[turn]--
case '>':
y[turn]++
case 'v':
x[turn]++
}
if _, ok := houses[x[turn]]; !ok {
houses[x[turn]] = make(map[int]bool)
}
houses[x[turn]][y[turn]] = true
if turn == 0 {
turn = 1
} else {
turn = 0
}
}
houseCount := 0
for x := range houses {
houseCount += len(houses[x])
}
return houseCount
}

1
inputs/3 Normal file

File diff suppressed because one or more lines are too long

1
inputs/3_test Normal file
View File

@ -0,0 +1 @@
>^>v<^v^v^v^v^v

View File

@ -4,6 +4,7 @@ import (
"aoc2015/aoclib" "aoc2015/aoclib"
"aoc2015/day01" "aoc2015/day01"
"aoc2015/day02" "aoc2015/day02"
"aoc2015/day03"
"flag" "flag"
"fmt" "fmt"
"os" "os"
@ -26,6 +27,9 @@ func initDayFunctions() {
dayFunctions[2] = make(map[int]func(puzzle aoclib.Puzzle) interface{}) dayFunctions[2] = make(map[int]func(puzzle aoclib.Puzzle) interface{})
dayFunctions[2][1] = day02.Part1 dayFunctions[2][1] = day02.Part1
dayFunctions[2][2] = day02.Part2 dayFunctions[2][2] = day02.Part2
dayFunctions[3] = make(map[int]func(puzzle aoclib.Puzzle) interface{})
dayFunctions[3][1] = day03.Part1
dayFunctions[3][2] = day03.Part2
} }
func execute(thisDay int) { func execute(thisDay int) {