33
6
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 it's 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 (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!
Can the output be an array of lines or a 2d array of chars? – ovs – 2017-07-24T11:23:13.167
@ovs Sorry thought I'd specified that, yes you can output an array or 2d array etc. Any reasonable format. – TheLethalCoder – 2017-07-24T11:26:15.020
In the case of a 2D array, can we use numbers for the bricks instead of characters? e.g.
[[1, " ", 1, " "], ...]
– Arnauld – 2017-07-24T13:27:03.700@Arnauld Yeah that seems fine. – TheLethalCoder – 2017-07-24T13:45:16.933
trailing whitespace is allowed? – Giuseppe – 2017-07-24T15:45:21.463
1@Giuseppe New lines only, otherwise it will be confused for empty bricks. – TheLethalCoder – 2017-07-24T15:46:44.670
may not
, notcannot
:P – Oliver Ni – 2017-07-25T02:50:35.003What's with the rule about base 10? It's all an int internally anyway, regardless if you parse the number in base 10 or base 2 or base 16… What's the point of this rule? – 2xsaiko – 2017-07-25T17:52:11.893
@therealfarfetchd One of the steps is to convert to base 2, it would be pretty pointless if you already took input in base 2... – TheLethalCoder – 2017-07-26T07:52:38.833
What would be different with for example in Java: Integer.parseInt("14", 10) and Integer.parseInt("E", 16)? They all yield int(14). But now I'm thinking you're thinking of not parsing the number at all, in which case, the rule makes sense. But then, again, when not parsing the number you don't have "an array of positive integers", but an array of strings. That probably just threw me off. I think I get it now though. – 2xsaiko – 2017-07-26T18:12:34.053