Created
January 3, 2019 11:41
-
-
Save Skarlso/13fad9cd707443d12b0f1c692a2d099c to your computer and use it in GitHub Desktop.
Complex numbers as coordinates
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
type WalkFunc func(a *complex128) | |
func main() { | |
coord := 0 + 0i; | |
up := func(a *complex128) { *a += (1+0i) } | |
left := func(a *complex128) { *a += (0+-1i) } | |
right := func(a *complex128) { *a += (0+1i) } | |
down := func(a *complex128) { *a += (-1+0i) } | |
mymap := make(map[complex128]bool, 0) | |
walkPath := []WalkFunc { | |
up, left, left, up, right, | |
up, up, up, left, down, | |
} | |
fmt.Println(coord) | |
mymap[coord] = true | |
for _, walk := range walkPath { | |
walk(&coord) | |
mymap[coord] = true | |
fmt.Println(coord) | |
} | |
fmt.Println(coord) | |
fmt.Println(mymap) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment