Created
March 22, 2020 12:09
-
-
Save rikkix/79f15b2eb20004a7329b25bfa648b745 to your computer and use it in GitHub Desktop.
This file contains 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" | |
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