rename directory

This commit is contained in:
VicRen
2020-10-22 14:04:57 +08:00
parent 66813aa5ca
commit acfe8ce353
18 changed files with 0 additions and 0 deletions
+41
View File
@@ -0,0 +1,41 @@
package main
import "fmt"
func main() {
num := 0
ml := 0
for i := 1000000; i > 1; i-- {
n := i
count := 1
for {
n = CollatzNext(n)
if n == 1 {
break
}
count++
}
if count > ml {
ml = count
num = i
}
}
fmt.Println("largest collatz is", num, "len:", ml)
}
func CollatzNext(n int) int {
if n == 1 {
return 1
} else if IsEven(n) {
return n / 2
} else {
return 3*n + 1
}
}
func IsEven(n int) bool {
if n > 1 && n%2 == 0 {
return true
}
return false
}