interplane.Get Omega
Read in your language

omega-rosetta

aien-dev/omega-rosetta

Brought by drakestapleton

branch main Branches Tags History

omega-rosetta / tasks / bell-numbers / oracle.py

17 lines · 623 bytes Raw Blame History
1# Independent reference for "Bell numbers" (Python 3, standard library only).
2# expected.txt is this program's stdout; omc never produced it.
3import math
4# Bell numbers by B(n+1) = sum C(n, k) B(k); the triangle rows by the Aitken array rule
5B = [1]
6for n in range(60):
7 B.append(sum(math.comb(n, k) * B[k] for k in range(n + 1)))
8print("first 10 rows of the Bell triangle:")
9r = [1]
10for i in range(10):
11 print(" ".join(map(str, r)))
12 nr = [r[-1]]
13 for v in r:
14 nr.append(nr[-1] + v)
15 r = nr
16print("first 15 Bell numbers: " + " ".join(map(str, B[:15])))
17print(f"B(49), the 50th Bell number: {B[49]}")