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 / count-in-factors.wiki

106 lines · 1801 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 x " x "
8text eqs " = "
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 prime factors in ascending order by trial division; 1 is shown as itself
36note bound: each pass divides v or steps d, and d * d <= v; for the inputs here d never passes 6857
37fn tell n ulong to void
38emitu n
39emit eqs
40if eq n 1
41emitu 1
42emit nl
43ret
44end
45v = n
46d = ulong 2
47f = ulong 0
48while le mul d d v bound 999999
49if eq rem v d 0
50if gt f 0
51emit x
52end
53emitu d
54f = add f 1
55v = div v d
56else
57d = add d 1
58end
59end
60if gt v 1
61if gt f 0
62emit x
63end
64emitu v
65end
66emit nl
67end
68fn main to int
69for i ulong 25
70tell add i 1
71end
72for i ulong 13
73tell add 2144 i
74end
75tell 600851475143
76tell 1000000000000
77ret 0
78end
79</syntaxhighlight>
80{{out}}
81<pre>
821 = 1
832 = 2
843 = 3
854 = 2 x 2
865 = 5
876 = 2 x 3
887 = 7
898 = 2 x 2 x 2
909 = 3 x 3
9110 = 2 x 5
9211 = 11
9312 = 2 x 2 x 3
9413 = 13
9514 = 2 x 7
9615 = 3 x 5
97...
982151 = 3 x 3 x 239
992152 = 2 x 2 x 2 x 269
1002153 = 2153
1012154 = 2 x 3 x 359
1022155 = 5 x 431
1032156 = 2 x 2 x 7 x 7 x 11
104600851475143 = 71 x 839 x 1471 x 6857
1051000000000000 = 2 x 2 x 2 x 2 x 2 x 2 x 2 x 2 x 2 x 2 x 2 x 2 x 5 x 5 x 5 x 5 x 5 x 5 x 5 x 5 x 5 x 5 x 5 x 5
106</pre>