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

96 lines · 2080 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 hdr "attractive numbers up to 120 (the count of prime factors, with multiplicity, is prime):\n"
8note emit writes every byte of a to stdout; a short write is retried, an error exits 1
9fn emit a view uchar * to void
10o = ulong 0
11while lt o len a bound 4096
12k = write 1 a o sub len a o
13if le k 0
14exit 1
15end
16o = add o ulong k
17end
18end
19note emitu writes n in decimal; 20 digits hold every ulong
20fn emitu n ulong to void
21d = new uchar 20 0
22i = ulong 20
23v = n
24while true bound 20
25i = sub i 1
26put d i uchar add rem v 10 48
27v = div v 10
28if eq v 0
29break
30end
31end
32emit part d i sub 20 i
33end
34note emitw writes n in decimal right-aligned in w columns (w at most 20)
35fn emitw n ulong w ulong to void
36d = new uchar 20 32
37i = ulong 20
38v = n
39while true bound 20
40i = sub i 1
41put d i uchar add rem v 10 48
42v = div v 10
43if eq v 0
44break
45end
46end
47if gt i sub 20 w
48i = sub 20 w
49end
50emit part d i sub 20 i
51end
52note Omega(n): the number of prime factors of n counted with multiplicity
53fn bigo n ulong to ulong
54v = n
55d = ulong 2
56k = ulong 0
57while le mul d d v bound 64
58if eq rem v d 0
59k = add k 1
60v = div v d
61else
62d = add d 1
63end
64end
65if gt v 1
66k = add k 1
67end
68ret k
69end
70note Omega(n) <= 6 for n <= 120, so the primes to test are 2, 3 and 5
71fn main to int
72emit hdr
73c = ulong 0
74for i ulong 120
75n = add i 1
76k = bigo n
77if or or eq k 2 eq k 3 eq k 5
78emitw n 4
79c = add c 1
80if eq rem c 20 0
81emit nl
82end
83end
84end
85emit nl
86ret 0
87end
88</syntaxhighlight>
89{{out}}
90<pre>
91attractive numbers up to 120 (the count of prime factors, with multiplicity, is prime):
92 4 6 8 9 10 12 14 15 18 20 21 22 25 26 27 28 30 32 33 34
93 35 38 39 42 44 45 46 48 49 50 51 52 55 57 58 62 63 65 66 68
94 69 70 72 74 75 76 77 78 80 82 85 86 87 91 92 93 94 95 98 99
95 102 105 106 108 110 111 112 114 115 116 117 118 119 120
96</pre>