定義
\[f(n) = \begin{cases} n / 2 & \text{if $n \equiv 0$} \\ 3 n + 1 & \text{if $n \equiv 1$} \end{cases}\]
Rustでの実装
fn coliatz(mut n: u64) { while n != 1 { println!("{}", n); if n % 2 == 0 { n = n / 2; } else { n = 3 * n + 1; } } println!("{}", n); }