KKSEWCX53GROLTUAA3IV2EPB6RDKA6RNWHRHFYX4NU6MR2GT4Q7AC
/*
Package collatzconjecture is for Collatz Conjecture related tasks.
*/
package collatzconjecture
import "errors"
// CollatzConjecture reports how many steps needed to reach 1
func CollatzConjecture(n int) (steps int, err error) {
if n < 1 {
return 0, errors.New("Negative input")
}
for {
if n == 1 {
return steps, nil
}
if n%2 == 0 {
// even
n = n / 2
} else {
// odd
n = 3*n + 1
}
steps++
}
}