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.
38 lines
485 B
38 lines
485 B
5 years ago
|
package main
|
||
5 years ago
|
|
||
5 years ago
|
import (
|
||
5 years ago
|
student "student"
|
||
|
|
||
|
"lib"
|
||
5 years ago
|
)
|
||
5 years ago
|
|
||
|
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
|
||
|
}
|
||
5 years ago
|
|
||
5 years ago
|
func main() {
|
||
5 years ago
|
args := append(lib.MultRandIntBetween(2, 20),
|
||
|
lib.RandIntBetween(-6, 20),
|
||
|
-5,
|
||
|
0,
|
||
|
)
|
||
5 years ago
|
for _, v := range args {
|
||
5 years ago
|
lib.Challenge("CollatzCountdown", student.CollatzCountdown, collatzCountdown, v)
|
||
5 years ago
|
}
|
||
|
}
|