mirror of https://github.com/01-edu/public.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
21 lines
231 B
21 lines
231 B
![]()
4 years ago
|
package solutions
|
||
|
|
||
|
func CollatzCountdown(start int) int {
|
||
|
if start <= 0 {
|
||
|
return -1
|
||
|
}
|
||
|
|
||
|
steps := 0
|
||
|
|
||
|
for start != 1 {
|
||
|
if start%2 == 0 {
|
||
|
start = start / 2
|
||
|
} else {
|
||
|
start = 3*start + 1
|
||
|
}
|
||
|
steps++
|
||
|
}
|
||
|
|
||
|
return steps
|
||
|
}
|