Skip to content

Instantly share code, notes, and snippets.

@crhntr
Created September 11, 2017 23:16
Show Gist options
  • Save crhntr/054b40a319091b6c654017893af8e8be to your computer and use it in GitHub Desktop.
Save crhntr/054b40a319091b6c654017893af8e8be to your computer and use it in GitHub Desktop.
package main
import "fmt"
func main() {
max := 1000
for a := 0; a < 8; a++ {
for b := 0; b < 8; b++ {
func(a, b int) {
initA := a
initB := b
i := 0
defer func() {
if i < max && i > 0 {
fmt.Printf("(a:%4d, b:%4d)\t%-4d\t(a:%4d, b:%4d)\n", initA, initB, i, a, b)
}
}()
history := [][2]int{}
for a > 0 {
if a < b {
a, b = 2*a, b-a
} else {
a, b = a-b, 2*b
}
i++
if i > max {
return
}
fmt.Printf("\t[step: %2d] (a:%4d, b:%4d)\n", i, a, b)
for _, tuple := range history {
if tuple[0] == a && tuple[1] == b {
fmt.Println("ERROR WILL LOOP")
return
}
}
history = append(history, [2]int{a, b})
}
}(a, b)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment