0 out of 464 challenges solved

Nth Centered Hexagonal Number

A centered hexagonal number is a figurate number that represents a hexagon with a dot in the center and all other dots surrounding the center dot in a hexagonal lattice. The formula to calculate the nth centered hexagonal number is:

\[ H_n = 3n(n-1) + 1 \]

Write a function `centered_hexagonal_number(n)` that takes an integer `n` and returns the nth centered hexagonal number.

#### Example Usage
```python [main.nopy]
centered_hexagonal_number(1)  # Output: 1
centered_hexagonal_number(2)  # Output: 7
centered_hexagonal_number(3)  # Output: 19
```

#### Constraints
- The input `n` will be a positive integer.
- The function should return an integer.
def centered_hexagonal_number(n):
    """
    Calculate the nth centered hexagonal number.

    Args:
        n (int): The position of the centered hexagonal number to calculate.

    Returns:
        int: The nth centered hexagonal number.
    """
    # Implement the formula for centered hexagonal numbers
    pass