0 out of 464 challenges solved
Write a function `bell_number(n)` that computes the nth Bell number. The Bell number represents the number of ways to partition a set of `n` elements into non-empty subsets.
#### Example Usage
```python [main.nopy]
print(bell_number(2)) # Output: 2
print(bell_number(3)) # Output: 5
print(bell_number(4)) # Output: 15
```
#### Explanation
- For `n = 2`, the set `{1, 2}` can be partitioned as `{{1}, {2}}` and `{{1, 2}}`, so there are 2 partitions.
- For `n = 3`, the set `{1, 2, 3}` can be partitioned in 5 ways: `{{1}, {2}, {3}}`, `{{1, 2}, {3}}`, `{{1, 3}, {2}}`, `{{2, 3}, {1}}`, and `{{1, 2, 3}}`.
Implement the function using dynamic programming for efficiency.def bell_number(n):
"""
Calculate the nth Bell number, which represents the number of ways to partition a set of n elements.
Args:
n (int): The number of elements in the set.
Returns:
int: The nth Bell number.
"""
# Placeholder for the solution
pass