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 / prime-decomposition.wiki

82 lines · 1492 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 eqs " = "
8text times " x "
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 trial division; d stays below 2^32 for these inputs, so mul d d does not wrap
36fn factor n ulong to void
37emitu n
38emit eqs
39v = n
40d = ulong 2
41first = true
42while le mul d d v bound 999999
43if eq rem v d 0
44if not first
45emit times
46end
47first = false
48emitu d
49v = div v d
50else
51d = add d 1
52end
53end
54if gt v 1
55if not first
56emit times
57end
58emitu v
59end
60emit nl
61end
62fn main to int
63factor 12
64factor 360
65factor 97
66factor 1001
67factor 2147483647
68factor 600851475143
69factor 18446744073709551615
70ret 0
71end
72</syntaxhighlight>
73{{out}}
74<pre>
7512 = 2 x 2 x 3
76360 = 2 x 2 x 2 x 3 x 3 x 5
7797 = 97
781001 = 7 x 11 x 13
792147483647 = 2147483647
80600851475143 = 71 x 839 x 1471 x 6857
8118446744073709551615 = 3 x 5 x 17 x 257 x 641 x 65537 x 6700417
82</pre>