```python
def bell_number(n):
    """
    Calculates the n-th Bell number, which is the number of ways to partition
    a set of n elements.
    """
    if n == 0:
        return 1

    # Initialize with the first row of the Bell triangle (for n=1)
    row = [1]

    # Compute rows for n=2, 3, ..., up to the target n
    for _ in range(1, n):
        last_element = row[-1]
        next_row = [last_element]

        # Calculate the elements of the next row
        for i in range(len(row)):
            new_element = next_row[i] + row[i]
            next_row.append(new_element)

        row = next_row

    # The n-th Bell number is the last element of the n-th row
    return row[-1]

```