For an integer n
that satisfies n > 0
, write its value as a right-descending path based on its binary representation.
Rules
- The first (most significant) set bit is always in the top-left corner.
- When the next bit is set (a
1
), draw a character ("filled") on the next line in the same column as the previous character drawn. Try to use spaces ("empty") to fill, but any character will do as long as it's always the same. - When the next bit is unset (a
0
), draw a character ("filled") on the same line immediately to the the right of the previous character drawn. - Your code must support numbers with at least 20 significant bits.
- Write a full program, a function, a lambda, etc. but no snippet.
- No leading spaces (or "empty" char) / lines allowed
- Any number of trailing spaces (or "empty" char) / lines allowed
- Any kind of 1D input is accepted: number, string, array of booleans, etc. Keep the order of bits untouched though.
- Any kind of visual 2D output is accepted: on stdout, a string (with any two distinct values representing "filled" and "empty"), you can even output a matrix if you want. A list of numbers seems hard to reconcile with the "no heading spaces" rule, but I'm open to it if you find a way to use it. Note: if you chose to print or return a string, the characters used must be ASCII characters in the codepoints range [32-126].
- Standard loopholes are banned.
- This is codegolf so the shortest code wins.
Examples
Input: 1
*
Input: 2
**
Input: 3
*
*
Input: 4
***
Input: 5
**
*
Input: 6
*
**
Input: 7
*
*
*
Input: 25
*
***
*
Input: 699050
**
**
**
**
**
**
**
**
**
**
Input: 1047552
*
*
*
*
*
*
*
*
*
***********
Input: 525311
**********
*
*
*
*
*
*
*
*
*
*
[1,0,1]
, yes. \$\endgroup\$9
is1001
I'd like my input to be0011
. Is that OK? \$\endgroup\$1
first is part of the challenge, and (re-)moving that bit would be trivializing the challenge so I'm afraid I'll have to say you no, @TonHospel . You can remove it from your input in the program, though. \$\endgroup\$