63 lines
757 B
Go
63 lines
757 B
Go
package main
|
|
|
|
import (
|
|
"bufio"
|
|
"fmt"
|
|
"os"
|
|
"strings"
|
|
)
|
|
|
|
func main() {
|
|
var moves []string = parseInput()
|
|
fmt.Println(moves)
|
|
x, y, z := 0, 0, 0
|
|
for _, m := range moves {
|
|
x, y, z = move(x, y, z, m)
|
|
fmt.Println(x, y, z)
|
|
}
|
|
fmt.Println("Result:", max(max(abs(x), abs(y)), abs(z)))
|
|
}
|
|
|
|
func parseInput() []string {
|
|
sc := bufio.NewScanner(os.Stdin)
|
|
sc.Scan()
|
|
return strings.Split(sc.Text(), ",")
|
|
}
|
|
|
|
func move(x, y, z int, m string) (int, int, int) {
|
|
switch m {
|
|
case "n":
|
|
y++
|
|
z--
|
|
case "ne":
|
|
x++
|
|
z--
|
|
case "se":
|
|
x++
|
|
y--
|
|
case "s":
|
|
y--
|
|
z++
|
|
case "sw":
|
|
x--
|
|
z++
|
|
case "nw":
|
|
x--
|
|
y++
|
|
}
|
|
return x, y, z
|
|
}
|
|
|
|
func abs(n int) int {
|
|
if n > 0 {
|
|
return n
|
|
}
|
|
return -n
|
|
}
|
|
func max(a, b int) int {
|
|
if a > b {
|
|
return a
|
|
}
|
|
return b
|
|
}
|