Compare commits

..

1 Commits

Author SHA1 Message Date
a3b2c6603e Day 3: spiral 2017-12-03 18:40:52 +01:00

View File

@ -7,6 +7,7 @@ import (
)
const (
// directions
W = iota
N
E
@ -14,14 +15,14 @@ const (
)
var (
// current value
cur int
x int
y int
// current position
x, y int
// current direction
dir int
xmax int
xmin int
ymax int
ymin int
// grid bounds
xmax, xmin, ymax, ymin int
)
func main() {
@ -29,15 +30,13 @@ func main() {
if err != nil {
os.Exit(1)
}
fmt.Println(n)
// create cell and compute change direction, expand grid
// move current position in grid and compute change direction, expand grid
for cur < n {
nextMove()
fmt.Println(cur, x, y)
// fmt.Println(cur, x, y)
}
fmt.Println("\n", Abs(x)+Abs(y))
// distance to position
fmt.Println(Abs(x) + Abs(y))
}
func nextMove() {