2
$\begingroup$

Inspired by this simple question at HackerRank, I was wondering if the following sequence has a closed-form:

$$a_0 = 1; \qquad a_n = \begin{cases} a_{n-1} + 1, & \text{if }n\text{ is even} \\[4pt] 2(a_{n-1}), & \text{if }n\text{ is odd} \end{cases}$$

For example, starting at $n=0$, we have:

$1,2,3,6,7,14,\ldots$

$\endgroup$
1
  • 2
    $\begingroup$ Look at this in binary. It will help you understand it better: 1, 10, 11, 110, 111, 1110, 1111, 11110, 11111, 111110, 111111 $\endgroup$ Commented Jun 21, 2014 at 17:35

2 Answers 2

7
$\begingroup$

$$a_{2n}=2^{n+1}-1,\qquad a_{2n+1}=2a_{2n}=2^{n+2}-2.$$

$\endgroup$
5
$\begingroup$

looks like those numbers are already tabulated,

https://oeis.org/A075427

$$a_n = \frac{(-1)^n}{2}+2^{n/2} \left(1+\sqrt{2}+(-1)^n \left(1-\sqrt{2}\right)\right)-\frac{3}{2}$$

formula by Paul Barry.

$\endgroup$
1
  • $\begingroup$ Accepting this because it's more what I had in mind as a solution $\endgroup$ Commented Jun 21, 2014 at 18:16

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.