Skip to content

Instantly share code, notes, and snippets.

@rikkix
Created March 22, 2020 12:09
Show Gist options
  • Save rikkix/79f15b2eb20004a7329b25bfa648b745 to your computer and use it in GitHub Desktop.
Save rikkix/79f15b2eb20004a7329b25bfa648b745 to your computer and use it in GitHub Desktop.
package main
import "fmt"
func Collatz(i uint64, round int) int {
if i < 2 {
return round
}
if i%2 == 0 {
return Collatz(i/2, round+1)
} else {
return Collatz(3*i+1, round+1)
}
}
func main() {
var max int
var collatzRange uint64 = 1e8
for ; collatzRange > 0; collatzRange-- {
round := Collatz(collatzRange, 0)
if round >= max {
max = round
fmt.Printf("%d: %d\n", round, collatzRange)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment