Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/si/rosetta/tasks/catalan-numbers/catalan-numbers.om # omega-mv Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance. Brought by drakestapleton Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / si / rosetta / tasks / catalan-numbers / catalan-numbers.om` 60 lines ยท 1239 bytes Raw Blame History 1 note Rosetta Code task "Catalan numbers": https://rosettacode.org/wiki/Catalan_numbers 2 note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 3 om2 4 text nl "\n" 5 text cc "C(" 6 text eqs ") = " 7 text by " by the recurrence, " 8 text sum " by the convolution sum\n" 9 text 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" 10 note emit writes every byte of a to stdout; a short write is retried, an error exits 1 11 fn emit a view uchar * to void 12 o = ulong 0 13 while lt o len a bound 4096 14 k = write 1 a o sub len a o 15 if le k 0 16 exit 1 17 end 18 o = add o ulong k 19 end 20 end 21 note emitu writes n in decimal; 20 digits hold every ulong 22 fn emitu n ulong to void 23 d = new uchar 20 0 24 i = ulong 20 25 v = n 26 while true bound 20 27 i = sub i 1 28 put d i uchar add rem v 10 48 29 v = div v 10 30 if eq v 0 31 break 32 end 33 end 34 emit part d i sub 20 i 35 end 36 note cs holds C(0)..C(14) from the convolution; all stay below 2^32, so every product fits 37 fn main to int 38 cs = new ulong 15 0 39 put cs 0 1 40 for n ulong 14 41 s = ulong 0 42 for i ulong add n 1 43 s = add s mul get cs i get cs sub n i 44 end 45 put cs add n 1 s 46 end 47 emit hdr 48 c = ulong 1 49 for n ulong 15 50 emit cc 51 emitu n 52 emit eqs 53 emitu c 54 emit by 55 emitu get cs n 56 emit sum 57 c = div mul c mul 2 add mul 2 n 1 add n 2 58 end 59 ret 0 60 end