adventofcode/2020/day12/main.go

44 lines
664 B
Go

package main
import (
"fmt"
h "git.bullercodeworks.com/brian/adventofcode/helpers"
)
const (
N = iota
E
S
W
)
func main() {
fmt.Println("# Day 12")
inp := h.StdinToStringSlice()
part1(inp)
part2(inp)
}
func part1(inp []string) {
s := Ship{
Pos: h.Coordinate{X: 0, Y: 0},
Dir: E,
}
s.Navigate(inp)
fmt.Println("## Part 1")
fmt.Println(s.Pos.Distance(h.Coordinate{X: 0, Y: 0}))
}
func part2(inp []string) {
s := Ship{
Pos: h.Coordinate{X: 0, Y: 0},
Dir: E,
Waypoint: h.Coordinate{X: 10, Y: -1},
ByWaypoint: true,
}
s.Navigate(inp)
fmt.Println("## Part 2")
fmt.Println(s.Pos.Distance(h.Coordinate{X: 0, Y: 0}))
}