+ import std.math; import std.typecons; - import std.math; /* - - Given a positive integer n, return a sorted array that has the odd numbers in collatz sequence. ? ---- + Given a positive integer n, return a sorted array that has the odd numbers in collatz sequence. - - The Collatz conjecture is a conjecture in mathematics that concerns a sequence defined ? ---- + The Collatz conjecture is a conjecture in mathematics that concerns a sequence defined - as follows: start with any positive integer n. Then each term is obtained from the ? ---- + as follows: start with any positive integer n. Then each term is obtained from the - previous term as follows: if the previous term is even, the next term is one half of ? ---- + previous term as follows: if the previous term is even, the next term is one half of - the previous term. If the previous term is odd, the next term is 3 times the previous ? ---- + the previous term. If the previous term is odd, the next term is 3 times the previous - term plus 1. The conjecture is that no matter what value of n, the sequence will always reach 1. ? ---- + term plus 1. The conjecture is that no matter what value of n, the sequence will always reach 1. - - Note: ? ---- + Note: - 1. Collatz(1) is [1]. ? ---- + 1. Collatz(1) is [1]. - 2. returned array sorted in increasing order. ? ---- + 2. returned array sorted in increasing order. - - For example: ? ---- + For example: - get_odd_collatz(5) returns [1, 5] # The collatz sequence for 5 is [5, 16, 8, 4, 2, 1], so the odd numbers are only 1, and 5. ? ---- + get_odd_collatz(5) returns [1, 5] # The collatz sequence for 5 is [5, 16, 8, 4, 2, 1], so the odd numbers are only 1, and 5. - >>> get_odd_collatz(5L) ? ---- + >>> get_odd_collatz(5L) - [1L, 5L] ? ---- + [1L, 5L] - */ long[] get_odd_collatz(long n)