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 (
// current value
cur int cur int
x int // current position
y int x, y int
// current direction
dir int dir int
xmax int // grid bounds
xmin int xmax, xmin, ymax, ymin int
ymax int
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() {