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 / factorial.wiki

74 lines · 1315 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 bang "! = "
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 recursive; 20! is the largest factorial that fits a ulong
35fn fact n ulong to ulong
36if eq n 0
37ret 1
38end
39ret mul n fact sub n 1
40end
41fn main to int
42for n ulong 21
43emitu n
44emit bang
45emitu fact n
46emit nl
47end
48ret 0
49end
50</syntaxhighlight>
51{{out}}
52<pre>
530! = 1
541! = 1
552! = 2
563! = 6
574! = 24
585! = 120
596! = 720
607! = 5040
618! = 40320
629! = 362880
6310! = 3628800
6411! = 39916800
6512! = 479001600
6613! = 6227020800
6714! = 87178291200
6815! = 1307674368000
6916! = 20922789888000
7017! = 355687428096000
7118! = 6402373705728000
7219! = 121645100408832000
7320! = 2432902008176640000
74</pre>