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

82 lines · 2320 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 cc "C("
8text eqs ") = "
9text by " by the recurrence, "
10text sum " by the convolution sum\n"
11text hdr "n, C(n) by C(n+1) = 2(2n+1)/(n+2) C(n), and again by C(n+1) = sum C(i) C(n-i):\n"
12note emit writes every byte of a to stdout; a short write is retried, an error exits 1
13fn emit a view uchar * to void
14o = ulong 0
15while lt o len a bound 4096
16k = write 1 a o sub len a o
17if le k 0
18exit 1
19end
20o = add o ulong k
21end
22end
23note emitu writes n in decimal; 20 digits hold every ulong
24fn emitu n ulong to void
25d = new uchar 20 0
26i = ulong 20
27v = n
28while true bound 20
29i = sub i 1
30put d i uchar add rem v 10 48
31v = div v 10
32if eq v 0
33break
34end
35end
36emit part d i sub 20 i
37end
38note cs holds C(0)..C(14) from the convolution; all stay below 2^32, so every product fits
39fn main to int
40cs = new ulong 15 0
41put cs 0 1
42for n ulong 14
43s = ulong 0
44for i ulong add n 1
45s = add s mul get cs i get cs sub n i
46end
47put cs add n 1 s
48end
49emit hdr
50c = ulong 1
51for n ulong 15
52emit cc
53emitu n
54emit eqs
55emitu c
56emit by
57emitu get cs n
58emit sum
59c = div mul c mul 2 add mul 2 n 1 add n 2
60end
61ret 0
62end
63</syntaxhighlight>
64{{out}}
65<pre>
66n, C(n) by C(n+1) = 2(2n+1)/(n+2) C(n), and again by C(n+1) = sum C(i) C(n-i):
67C(0) = 1 by the recurrence, 1 by the convolution sum
68C(1) = 1 by the recurrence, 1 by the convolution sum
69C(2) = 2 by the recurrence, 2 by the convolution sum
70C(3) = 5 by the recurrence, 5 by the convolution sum
71C(4) = 14 by the recurrence, 14 by the convolution sum
72C(5) = 42 by the recurrence, 42 by the convolution sum
73C(6) = 132 by the recurrence, 132 by the convolution sum
74C(7) = 429 by the recurrence, 429 by the convolution sum
75C(8) = 1430 by the recurrence, 1430 by the convolution sum
76C(9) = 4862 by the recurrence, 4862 by the convolution sum
77C(10) = 16796 by the recurrence, 16796 by the convolution sum
78C(11) = 58786 by the recurrence, 58786 by the convolution sum
79C(12) = 208012 by the recurrence, 208012 by the convolution sum
80C(13) = 742900 by the recurrence, 742900 by the convolution sum
81C(14) = 2674440 by the recurrence, 2674440 by the convolution sum
82</pre>