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

66 lines · 1191 bytes Raw Blame History
1note Rosetta Code task "Anti-primes": https://rosettacode.org/wiki/Anti-primes
2note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3om2
4text nl "\n"
5text sp " "
6text first "first 20 anti-primes:"
7note emit writes every byte of a to stdout; a short write is retried, an error exits 1
8fn emit a view uchar * to void
9o = ulong 0
10while lt o len a bound 4096
11k = write 1 a o sub len a o
12if le k 0
13exit 1
14end
15o = add o ulong k
16end
17end
18note emitu writes n in decimal; 20 digits hold every ulong
19fn emitu n ulong to void
20d = new uchar 20 0
21i = ulong 20
22v = n
23while true bound 20
24i = sub i 1
25put d i uchar add rem v 10 48
26v = div v 10
27if eq v 0
28break
29end
30end
31emit part d i sub 20 i
32end
33note divisor count by pairing d with n / d for d * d <= n
34fn ndiv n ulong to ulong
35c = ulong 0
36d = ulong 1
37while le mul d d n bound 100
38if eq rem n d 0
39c = add c 2
40if eq mul d d n
41c = sub c 1
42end
43end
44d = add d 1
45end
46ret c
47end
48note an anti-prime has more divisors than every smaller positive integer; the 20th is 7560
49fn main to int
50emit first
51best = ulong 0
52c = ulong 0
53n = ulong 1
54while lt c 20 bound 7560
55k = ndiv n
56if gt k best
57best = k
58emit sp
59emitu n
60c = add c 1
61end
62n = add n 1
63end
64emit nl
65ret 0
66end