interplane.Get Omega
Read in your language

omega-rosetta

aien-dev/omega-rosetta

Brought by drakestapleton

branch main Branches Tags History

omega-rosetta / drafts / rosettacode / almost-prime.wiki

83 lines · 1544 bytes Raw Blame History
1=={{header|Omegese}}==
2{{works with|omc|sha256 2c824805, aien-dev/omega-mv e5b32567, Linux AArch64}}
3Omega has no imports, so the small output helpers (<code>emit</code> and friends) are part of the program.
4<syntaxhighlight lang="text">
5om2
6text nl "\n"
7text sp " "
8text kk "k = "
9text col ":"
10note emit writes every byte of a to stdout; a short write is retried, an error exits 1
11fn emit a view uchar * to void
12o = ulong 0
13while lt o len a bound 4096
14k = write 1 a o sub len a o
15if le k 0
16exit 1
17end
18o = add o ulong k
19end
20end
21note emitu writes n in decimal; 20 digits hold every ulong
22fn emitu n ulong to void
23d = new uchar 20 0
24i = ulong 20
25v = n
26while true bound 20
27i = sub i 1
28put d i uchar add rem v 10 48
29v = div v 10
30if eq v 0
31break
32end
33end
34emit part d i sub 20 i
35end
36note a k-almost prime has exactly k prime factors counted with multiplicity
37fn bigo n ulong to ulong
38v = n
39d = ulong 2
40k = ulong 0
41while le mul d d v bound 64
42if eq rem v d 0
43k = add k 1
44v = div v d
45else
46d = add d 1
47end
48end
49if gt v 1
50k = add k 1
51end
52ret k
53end
54note bound: the 10th 5-almost prime is 176, so no list needs more than 200 candidates
55fn main to int
56for j ulong 5
57k = add j 1
58emit kk
59emitu k
60emit col
61c = ulong 0
62n = ulong 2
63while lt c 10 bound 200
64if eq bigo n k
65emit sp
66emitu n
67c = add c 1
68end
69n = add n 1
70end
71emit nl
72end
73ret 0
74end
75</syntaxhighlight>
76{{out}}
77<pre>
78k = 1: 2 3 5 7 11 13 17 19 23 29
79k = 2: 4 6 9 10 14 15 21 22 25 26
80k = 3: 8 12 18 20 27 28 30 42 44 45
81k = 4: 16 24 36 40 54 56 60 81 84 88
82k = 5: 32 48 72 80 108 112 120 162 168 176
83</pre>