2017 Day 11 Done
This commit is contained in:
parent
58d319b4c0
commit
2f65fcff50
58
2017/day11/day11.go
Normal file
58
2017/day11/day11.go
Normal 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
1
2017/day11/input
Normal file
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user