interplane.Get Omega
Read in your language

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

branch main Branches Tags History

omega-mv / si / rosetta / tasks / almost-prime / almost-prime.om

72 lines · 1225 bytes Raw Blame History
1note Rosetta Code task "Almost prime": https://rosettacode.org/wiki/Almost_prime
2note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3om2
4text nl "\n"
5text sp " "
6text kk "k = "
7text col ":"
8note emit writes every byte of a to stdout; a short write is retried, an error exits 1
9fn emit a view uchar * to void
10o = ulong 0
11while lt o len a bound 4096
12k = write 1 a o sub len a o
13if le k 0
14exit 1
15end
16o = add o ulong k
17end
18end
19note emitu writes n in decimal; 20 digits hold every ulong
20fn emitu n ulong to void
21d = new uchar 20 0
22i = ulong 20
23v = n
24while true bound 20
25i = sub i 1
26put d i uchar add rem v 10 48
27v = div v 10
28if eq v 0
29break
30end
31end
32emit part d i sub 20 i
33end
34note a k-almost prime has exactly k prime factors counted with multiplicity
35fn bigo n ulong to ulong
36v = n
37d = ulong 2
38k = ulong 0
39while le mul d d v bound 64
40if eq rem v d 0
41k = add k 1
42v = div v d
43else
44d = add d 1
45end
46end
47if gt v 1
48k = add k 1
49end
50ret k
51end
52note bound: the 10th 5-almost prime is 176, so no list needs more than 200 candidates
53fn main to int
54for j ulong 5
55k = add j 1
56emit kk
57emitu k
58emit col
59c = ulong 0
60n = ulong 2
61while lt c 10 bound 200
62if eq bigo n k
63emit sp
64emitu n
65c = add c 1
66end
67n = add n 1
68end
69emit nl
70end
71ret 0
72end