interplane.Get Omega
Read in your language

omega-rosetta

aien-dev/omega-rosetta

Brought by drakestapleton

branch main Branches Tags History

omega-rosetta / exercises / nth-prime / .meta / example.om

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