adventofcode/2017/day11/day11.go

59 lines
947 B
Go
Raw Normal View History

2017-12-11 12:54:07 +00:00
package main
import (
"bufio"
"fmt"
"math"
"os"
"strings"
)
func main() {
inp := strings.ToLower(StdinToString())
dirs := strings.Split(inp, ",")
var currX, currY, currZ int
var furthest float64
for i := range dirs {
switch dirs[i] {
case "n":
currY++
currZ--
case "ne":
currX++
currZ--
case "se":
currY--
currX++
case "s":
currY--
currZ++
case "sw":
currX--
currZ++
case "nw":
currY++
currX--
}
if math.Abs(float64(currX)) > furthest {
furthest = math.Abs(float64(currX))
}
if math.Abs(float64(currY)) > furthest {
furthest = math.Abs(float64(currY))
}
if math.Abs(float64(currZ)) > furthest {
furthest = math.Abs(float64(currZ))
}
}
fmt.Println(currY, currX, currZ)
fmt.Println("Furthest:", furthest)
}
func StdinToString() string {
var input string
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
input = scanner.Text()
}
return input
}