Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,43 @@
public struct BellTriangle<T: BinaryInteger> {
@usableFromInline
var arr: [T]
@inlinable
public internal(set) subscript(row row: Int, col col: Int) -> T {
get { arr[row * (row - 1) / 2 + col] }
set { arr[row * (row - 1) / 2 + col] = newValue }
}
@inlinable
public init(n: Int) {
arr = Array(repeating: 0, count: n * (n + 1) / 2)
self[row: 1, col: 0] = 1
for i in 2...n {
self[row: i, col: 0] = self[row: i - 1, col: i - 2]
for j in 1..<i {
self[row: i, col: j] = self[row: i, col: j - 1] + self[row: i - 1, col: j - 1]
}
}
}
}
let tri = BellTriangle<Int>(n: 15)
print("First 15 Bell numbers:")
for i in 1...15 {
print("\(i): \(tri[row: i, col: 0])")
}
for i in 1...10 {
print(tri[row: i, col: 0], terminator: "")
for j in 1..<i {
print(", \(tri[row: i, col: j])", terminator: "")
}
print()
}