← Back to challenges

Baum-Sweet Sequence

JavaScriptHardmathnumbers

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

baumSweet(0) ➞ "0"

baumSweet(1) ➞ "01"

baumSweet(10) ➞ "01011001010"

Notes

For all cases, n >= 0.

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