Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them.
Page: /drakestapleton/omega-rosetta/blob/main/drafts/rosettacode/anti-primes.wiki
# omega-rosetta
aien-dev/omega-rosetta
Brought by drakestapleton
Sign in to star 0 stars 0 watching
About Files History Releases Proposed changes Issues For developers
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}}
3 Omega has no imports, so the small output helpers (emit and friends) are part of the program.
4
5 om2
6 text nl "\n"
7 text sp " "
8 text first "first 20 anti-primes:"
9 note emit writes every byte of a to stdout; a short write is retried, an error exits 1
10 fn emit a view uchar * to void
11 o = ulong 0
12 while lt o len a bound 4096
13 k = write 1 a o sub len a o
14 if le k 0
15 exit 1
16 end
17 o = add o ulong k
18 end
19 end
20 note emitu writes n in decimal; 20 digits hold every ulong
21 fn emitu n ulong to void
22 d = new uchar 20 0
23 i = ulong 20
24 v = n
25 while true bound 20
26 i = sub i 1
27 put d i uchar add rem v 10 48
28 v = div v 10
29 if eq v 0
30 break
31 end
32 end
33 emit part d i sub 20 i
34 end
35 note divisor count by pairing d with n / d for d * d <= n
36 fn ndiv n ulong to ulong
37 c = ulong 0
38 d = ulong 1
39 while le mul d d n bound 100
40 if eq rem n d 0
41 c = add c 2
42 if eq mul d d n
43 c = sub c 1
44 end
45 end
46 d = add d 1
47 end
48 ret c
49 end
50 note an anti-prime has more divisors than every smaller positive integer; the 20th is 7560
51 fn main to int
52 emit first
53 best = ulong 0
54 c = ulong 0
55 n = ulong 1
56 while lt c 20 bound 7560
57 k = ndiv n
58 if gt k best
59 best = k
60 emit sp
61 emitu n
62 c = add c 1
63 end
64 n = add n 1
65 end
66 emit nl
67 ret 0
68 end
69
70 {{out}}
71
72 first 20 anti-primes: 1 2 4 6 12 24 36 48 60 120 180 240 360 720 840 1260 1680 2520 5040 7560
73