Skip to content

Instantly share code, notes, and snippets.

@Skarlso
Created January 3, 2019 11:41
Show Gist options
  • Save Skarlso/13fad9cd707443d12b0f1c692a2d099c to your computer and use it in GitHub Desktop.
Save Skarlso/13fad9cd707443d12b0f1c692a2d099c to your computer and use it in GitHub Desktop.
Complex numbers as coordinates
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