day03
This commit is contained in:
parent
c026df5d0a
commit
aff0fbe573
74
day03/day03.go
Normal file
74
day03/day03.go
Normal 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_test
Normal file
1
inputs/3_test
Normal file
@ -0,0 +1 @@
|
|||||||
|
>^>v<^v^v^v^v^v
|
||||||
4
main.go
4
main.go
@ -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) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user