Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func steps(n uint64) uint64 {
- if n <= 0 { return 0; }
- if n == 1 { return 0; }
- var steps uint64
- i := n
- for i != 1 {
- for (i & 1) == 1 {
- i = ((3 * i) + 1) / 2
- steps += 2
- }
- for (i & 1) == 0 {
- i /= 2
- steps++
- }
- }
- return steps
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement