0 out of 464 challenges solved
### Problem Statement The Jacobsthal numbers are a sequence of integers defined by the recurrence relation: \[ J(n) = \begin{cases} 0 & \text{if } n = 0, \\ 1 & \text{if } n = 1, \\ J(n-1) + 2 \cdot J(n-2) & \text{if } n > 1. \end{cases} \] Write a function `jacobsthal_num(n)` that computes the nth Jacobsthal number. ### Example Usage ```python [main.nopy] jacobsthal_num(0) # Output: 0 jacobsthal_num(1) # Output: 1 jacobsthal_num(5) # Output: 11 jacobsthal_num(10) # Output: 341 ``` ### Constraints - The input `n` will be a non-negative integer. - The function should be efficient for values of `n` up to 20.
def jacobsthal_num(n): """ Calculate the nth Jacobsthal number. Args: n (int): The index of the Jacobsthal number to compute. Returns: int: The nth Jacobsthal number. """ # Implement the function logic here pass