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 / anti-primes.wiki

73 lines · 1423 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 first "first 20 anti-primes:"
9note emit writes every byte of a to stdout; a short write is retried, an error exits 1
10fn emit a view uchar * to void
11o = ulong 0
12while lt o len a bound 4096
13k = write 1 a o sub len a o
14if le k 0
15exit 1
16end
17o = add o ulong k
18end
19end
20note emitu writes n in decimal; 20 digits hold every ulong
21fn emitu n ulong to void
22d = new uchar 20 0
23i = ulong 20
24v = n
25while true bound 20
26i = sub i 1
27put d i uchar add rem v 10 48
28v = div v 10
29if eq v 0
30break
31end
32end
33emit part d i sub 20 i
34end
35note divisor count by pairing d with n / d for d * d <= n
36fn ndiv n ulong to ulong
37c = ulong 0
38d = ulong 1
39while le mul d d n bound 100
40if eq rem n d 0
41c = add c 2
42if eq mul d d n
43c = sub c 1
44end
45end
46d = add d 1
47end
48ret c
49end
50note an anti-prime has more divisors than every smaller positive integer; the 20th is 7560
51fn main to int
52emit first
53best = ulong 0
54c = ulong 0
55n = ulong 1
56while lt c 20 bound 7560
57k = ndiv n
58if gt k best
59best = k
60emit sp
61emitu n
62c = add c 1
63end
64n = add n 1
65end
66emit nl
67ret 0
68end
69</syntaxhighlight>
70{{out}}
71<pre>
72first 20 anti-primes: 1 2 4 6 12 24 36 48 60 120 180 240 360 720 840 1260 1680 2520 5040 7560
73</pre>