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