Compare commits

..

1 Commits

Author SHA1 Message Date
08f7db87ad Day 3: spiral 2017-12-03 18:20:57 +01:00

View File

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