hackathon/question/q01/part1.go

27 lines
416 B
Go

package q01
import "strconv"
func move(x, y int, dir byte, step int) (int, int) {
switch dir {
case 'N':
return x, y + step
case 'S':
return x, y - step
case 'E':
return x + step, y
case 'W':
return x - step, y
}
return x, y
}
func solveP1(steps []string) (x int, y int) {
for _, step := range steps {
dir := step[0]
amt, _ := strconv.Atoi(step[1:])
x, y = move(x, y, dir, amt)
}
return
}