omega-mv
Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.
Brought by drakestapleton
omega-mv / tests / compiler / progs / collatz.osc
| 1 | // entry: collatz |
| 2 | // expect-run: collatz 27 -> 111 |
| 3 | // expect-run: collatz 1 -> 0 |
| 4 | // expect-run: collatz 0 -> trap=LOOP_BOUND |
| 5 | // Collatz steps with a static bound: very long or endless orbits trap LOOP_BOUND. |
| 6 | fn collatz(n0: u32) -> u32 { |
| 7 | let mut n: u64 = n0 as u64; |
| 8 | let mut steps: u32 = 0; |
| 9 | while n != 1 bound 300 { |
| 10 | if n % 2 == 0 { n = n / 2; } else { n = 3 * n + 1; } |
| 11 | steps = steps + 1; |
| 12 | } |
| 13 | return steps; |
| 14 | } |