Stern's Diatomic

HardAcc. 71.6%
+45 XP 25

The Binomial Alternative

Stern's diatomic sequence $s_n$ is defined as: $s_0 = 0, s_1 = 1$ $s_{2n} = s_n$ $s_{2n+1} = s_n + s_{n+1}$

The Assignment

Your function receives a parameter n.

  1. use a loop to build the sequence up to n.
  2. Print only the n-th value (s[n]).

01EXAMPLE 1

Inputn = 3
Output2

Explanation: s0=0, s1=1, s2=1, s3=1+1=2.

Constraints

  • Iterative implementation.
  • Result is a single number.
MathLoopsLogic
JavaScript
Loading...
3 Hidden

Input Arguments

n3

Expected Output

2

Click RUN to test your solution