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 (
// directions
W = iota
N
E
@ -15,14 +14,14 @@ const (
)
var (
// current value
cur int
// current position
x, y int
// current direction
dir int
// grid bounds
xmax, xmin, ymax, ymin int
cur int
x int
y int
dir int
xmax int
xmin int
ymax int
ymin int
)
func main() {
@ -30,13 +29,15 @@ func main() {
if err != nil {
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 {
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() {