← Back to challenges

Baum-Sweet Sequence

PythonHardmathnumbers

Instructions

Create a function that takes a number n and returns all the terms of the Baum-Sweet sequence, from 0 to n (included).

The Baum-Sweet sequence is the sequence of numbers bi such that bi = 1 if the binary representation of i contains no block of consecutive 0 of odd length, and bi = 0 otherwise.

Examples

baum_sweet(0) ➞ "0"

baum_sweet(1) ➞ "01"

baum_sweet(10) ➞ "01011001010"

Notes

For all cases, n >= 0.

python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.