omega-rosetta
aien-dev/omega-rosetta
Brought by drakestapleton
omega-rosetta / exercises / nth-prime / .meta / example.om
| 1 | note Exercism-style exercise "nth-prime": https://exercism.org/tracks/python/exercises/nth-prime |
| 2 | note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 3 | note prime is the n-th prime number (prime 1 is 2), or 0 for n = 0, which has no prime. |
| 4 | note Check it with: sh exercise.sh exercises/nth-prime |
| 5 | om2 |
| 6 | fn isprime n ulong to bool |
| 7 | d = ulong 2 |
| 8 | while le mul d d n bound 999999 |
| 9 | if eq rem n d 0 |
| 10 | ret false |
| 11 | end |
| 12 | d = add d 1 |
| 13 | end |
| 14 | ret true |
| 15 | end |
| 16 | fn prime n ulong to ulong |
| 17 | if eq n 0 |
| 18 | ret 0 |
| 19 | end |
| 20 | c = ulong 0 |
| 21 | v = ulong 1 |
| 22 | while lt c n bound 999999 |
| 23 | v = add v 1 |
| 24 | if isprime v |
| 25 | c = add c 1 |
| 26 | end |
| 27 | end |
| 28 | ret v |
| 29 | end |