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