2017 Day 11 Done

This commit is contained in:
Brian Buller 2017-12-11 06:54:07 -06:00
parent 58d319b4c0
commit 2f65fcff50
2 changed files with 59 additions and 0 deletions

58
2017/day11/day11.go Normal file
View File

@ -0,0 +1,58 @@
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
}

1
2017/day11/input Normal file

File diff suppressed because one or more lines are too long