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 / pernicious-numbers.wiki

88 lines · 1721 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 25 pernicious numbers:"
9text range "pernicious numbers from 888888877 to 888888888:"
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
36fn popc n ulong to ulong
37c = ulong 0
38v = n
39while gt v 0 bound 64
40c = add c and v 1
41v = shr v 1
42end
43ret c
44end
45note a pernicious number has a prime population count; counts here are at most 30, so trial division is enough
46fn isprime n ulong to bool
47if lt n 2
48ret false
49end
50d = ulong 2
51while le mul d d n bound 8
52if eq rem n d 0
53ret false
54end
55d = add d 1
56end
57ret true
58end
59fn main to int
60emit first
61c = ulong 0
62n = ulong 1
63while lt c 25 bound 100
64if isprime popc n
65emit sp
66emitu n
67c = add c 1
68end
69n = add n 1
70end
71emit nl
72emit range
73for i ulong 12
74n = add 888888877 i
75if isprime popc n
76emit sp
77emitu n
78end
79end
80emit nl
81ret 0
82end
83</syntaxhighlight>
84{{out}}
85<pre>
86first 25 pernicious numbers: 3 5 6 7 9 10 11 12 13 14 17 18 19 20 21 22 24 25 26 28 31 33 34 35 36
87pernicious numbers from 888888877 to 888888888: 888888877 888888878 888888880 888888883 888888885 888888886
88</pre>