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-rosetta/blob/main/drafts/rosettacode/bell-numbers.wiki # omega-rosetta aien-dev/omega-rosetta Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-rosetta / drafts / rosettacode / bell-numbers.wiki` 132 lines ยท 2803 bytes Raw Blame History 1 =={{header|Omegese}}== 2 {{works with|omc|sha256 `2c824805`, aien-dev/omega-mv `e5b32567`, Linux AArch64}} 3 Omega has no imports, so the small output helpers (emit and friends) are part of the program. 4 5 om2 6 text nl "\n" 7 text sp " " 8 text tri "first 10 rows of the Bell triangle:\n" 9 text first "first 15 Bell numbers:" 10 text b49 "B(49), the 50th Bell number: " 11 note a triangle row of up to 50 entries; entry e is 6 limbs base 10^9 at 6e..6e+5, least significant first 12 note 6 limbs hold below 10^54; the largest entry needed, in row 49, is below B(50) < 2 * 10^47 13 global pv ulong 300 14 global cu ulong 300 15 note emit writes every byte of a to stdout; a short write is retried, an error exits 1 16 fn emit a view uchar * to void 17 o = ulong 0 18 while lt o len a bound 4096 19 k = write 1 a o sub len a o 20 if le k 0 21 exit 1 22 end 23 o = add o ulong k 24 end 25 end 26 note emitu writes n in decimal; 20 digits hold every ulong 27 fn emitu n ulong to void 28 d = new uchar 20 0 29 i = ulong 20 30 v = n 31 while true bound 20 32 i = sub i 1 33 put d i uchar add rem v 10 48 34 v = div v 10 35 if eq v 0 36 break 37 end 38 end 39 emit part d i sub 20 i 40 end 41 note row i of the Bell triangle starts with the last entry of row i - 1; each next entry adds the entry 42 note to its left and the entry above that one. Row i - 1 sits in pv and row i is built in cu, then copied 43 fn bellrow i ulong to void 44 for l ulong 6 45 put cu l get pv add mul sub i 1 6 l 46 end 47 for j ulong i 48 c = ulong 0 49 for l ulong 6 50 o = add mul j 6 l 51 s = add get cu o c 52 s = add s get pv o 53 put cu add o 6 rem s `1000000000` 54 c = div s `1000000000` 55 end 56 end 57 for t ulong mul add i 1 6 58 put pv t get cu t 59 end 60 end 61 note pv entry 0 in decimal: the top non-zero limb, then each lower limb padded to 9 digits 62 fn emitb to void 63 k = ulong 5 64 while and gt k 0 eq get pv k 0 bound 6 65 k = sub k 1 66 end 67 emitu get pv k 68 for t ulong k 69 v = get pv sub sub k 1 t 70 d = ulong `100000000` 71 while gt d 0 bound 9 72 emitu rem div v d 10 73 d = div d 10 74 end 75 end 76 end 77 fn main to int 78 bs = new ulong 15 0 79 put pv 0 1 80 put bs 0 1 81 emit tri 82 emitu 1 83 emit nl 84 i = ulong 1 85 while le i 49 bound 49 86 bellrow i 87 if lt i 10 88 for j ulong add i 1 89 if gt j 0 90 emit sp 91 end 92 emitu get pv mul j 6 93 end 94 emit nl 95 end 96 if lt i 15 97 put bs i get pv 0 98 end 99 if lt i 49 100 i = add i 1 101 else 102 break 103 end 104 end 105 emit first 106 for j ulong 15 107 emit sp 108 emitu get bs j 109 end 110 emit nl 111 emit b49 112 emitb 113 emit nl 114 ret 0 115 end 116 117 {{out}} 118

119 first 10 rows of the Bell triangle:

120 1

121 1 2

122 2 3 5

123 5 7 10 15

124 15 20 27 37 52

125 52 67 87 114 151 203

126 203 255 322 409 523 674 877

127 877 1080 1335 1657 2066 2589 3263 4140

128 4140 5017 6097 7432 9089 11155 13744 17007 21147

129 21147 25287 30304 36401 43833 52922 64077 77821 94828 115975

130 first 15 Bell numbers: 1 1 2 5 15 52 203 877 4140 21147 115975 678570 `4213597` `27644437` `190899322`

131 B(49), the 50th Bell number: `10726137154573358400342215518590002633917247281`

132