Given an array of positive integers in base 10, where n > 0
, output their representation of a binary wall.
How does this work?
- Convert each number to its binary representation.
- Pad the representation with leading zeroes to the length of the longest one i.e.
1, 2
->1, 10
->01, 10
. - Create a wall where the
1
s are bricks and0
s are missing bricks.
A wall is a block of characters where any printable character represents a brick and a space (ASCII decimal code 32
) represents a missing brick. You may choose any character for the brick, it need not be distinct across the wall as long as it isn't a white space character. The missing brick character must be a space. For the example below I have used *
for the bricks.
Example
Input:
[ 15, 7, 13, 11 ]
[ 1111, 111, 1101, 1011 ]
[ 1111, 0111, 1101, 1011 ]
Output:
**** *** ** * * **
Rules
- Input must be taken in base 10, if your language accepts other bases you may not use them.
- Leading and trailing new lines are allowed.
- Input may be taken as a list of integers, separate arguments or any reasonable format.
- Output may be in any reasonable format: new line separated string, array of lines, 2d array etc.
- Standard loopholes are disallowed.
Test Cases
Note that in the first test case all of layers have an empty brick at the end.
[ 14, 4, 6, 2 ]
***
*
**
*
[ 1, 2, 4, 8, 16 ]
*
*
*
*
*
[ 15, 11, 15, 15 ]
****
* **
****
****
[ 11, 10, 9, 8 ]
* **
* *
* *
*
This is code golf so shortest code wins!
[[1, " ", 1, " "], ...]
\$\endgroup\$