# Binary Slashes Display

(easy mode of Seven Slash Display)

Given a positive integer (or alternatively, a string/list of bits of its binary representation) output it with this diagonal ASCII-art formation:

(output for 53 / 110101)

       \
/\ \
\ \
\ \/
/\ \
\ \
\ \/
\ \
\


This output has the MSB at the bottom left. Alternatively, you may choose to output with the LSB at the bottom left.

The output may include any extra whitespace as long as that doesn’t impact the presentation of the image.

This is a competition, so the shortest code wins.

# Charcoal, 23 17 bytes

ＦＳ¿Σι↗\«\↑/↗\»‖Ｍ↖


Try it online! Link is to verbose version of code. Takes input as a binary string. Explanation:

ＦＳ


Loop over each digit.

¿Σι


If it's a 1, then...

↗\


... output the bottom half of the 1, finishing with the cursor moved up and right.

«\↑/↗\»


Otherwise, draw the bottom half of the zero, finishing with the cursor moved up and right.

‖Ｍ↖


Reflect to complete the output.

Alternative solution, also 17 bytes:

ＦＳ«Ｆ¬Σι↑\¶/↗\»‖Ｍ↖


Try it online! Link is to verbose version of code. Explanation:

ＦＳ«


Loop over each digit.

Ｆ¬Σι


If it's a zero, then...

↑\¶/


... draw the \/ part.

↗\


Draw the bottom half of the 1 or complete the bottom half of the zero, finishing with the cursor moved up and right.

»‖Ｍ↖


Reflect to complete the output.

Edit: Saved 6 bytes by using ReflectMirror(:UpLeft); as suggested by @noodleman.

• Nice solution! I initially posted this as a CMC in the TNB discord server, and somebody found a 20 byte Charcoal solution, and that takes the input as decimal, I wonder if you can find it? :) Hint: ReflectMirror(:UpLeft); Commented Jun 25 at 0:19
• I found two solutions using ReflectMirror(:UpLeft);, but they weren't 20 bytes...
– Neil
Commented Jun 25 at 7:19
• Nice improvement! The person who had the original 20 bytes suggests using array input instead of string input to save another byte: Try it online! Commented Jun 25 at 10:47
• Oh, you said input as decimal, well, in that case, it would cost two bytes to convert that to an array, but as you point out, the array then saves a byte, so it's still only 18 bytes, not 20: Try it online!
– Neil
Commented Jun 25 at 12:43
• I don’t understand your comment, I’m saying that this solution you wrote can be a byte shorter by taking the input as a list of binary digits rather than as a binary string. The other person’s original solution was 20 bytes by taking input as decimal or 18 bytes taking it as a binary string, so your solution is definitely shorter, they found the array-input improvement after looking at yours Commented Jun 25 at 15:46

# Python 3.8 (pre-release),  263  243  229  226  225  187  168  151  150 bytes

-20 bytes by applying some small modifications.
-14 bytes by emanresu A.
-3 bytes by noodle person.
-75 bytes by ASCII-only.
-1 byte by noodle person.

…Okay, what—

def f(b,c=[]):
for i in b:c+=[0,1,2][i::2]
for i in range(l:=len(c),-1,-1):print(" "*i+"  /"[[0,*c][i]]+" \\"[i>0]+" \\"*(i<l)+"  /"[[*c,0,0][i+1]])


Try it online!

• 229 Commented Jun 25 at 6:01
• Building on emanresu A's suggestion, you can alias range to r to save another 3 bytes. Try it online! Commented Jun 25 at 10:30
• and another -1 Commented Jun 25 at 10:52
• 187 Commented Jun 25 at 11:03
• 168 Commented Jun 25 at 11:10

# J, 78 bytes

' \/'{~[:+&(+|:&.|.)/1 2([*Q=/~([+|.@Q=:i.@#@])*_ 1{~]>.~2-[)"{0,&;(0 1;0){~|.


Try it online!

Accepts input as a list of binary digits. Here's the expanded version I started with, which shows some of the symmetry:

b =: 1 1 0 1 0 1

e =: [ + i.@-@#@]

T =: 1 * (mT           ) =/ i.#mask

echo ' \/' {~ (+|:&.|.) K+T


Try it online!

# Zsh, 88 bytes

for b;((b))&&L=(\ $^L \$l)&&l=' \'||{L=(' '^L '/\'l '\ \');l=' \/' } print -rl L l  Try it online! Or add --rcexpandparam to remove the ^ for 86 bytes. for bit; ((bit)) && # prepend all but one of the previous lines with a space, # the last line prefixed with a '\' lines=(\ ^lines \$last) && # new last line is ' \' last=' \' || { # prepend all but one of the previous lines with two spaces, # the last line prefixed with a '/\', # add '\ \' as the center of the zero lines=(' '$^lines '/\'$last '\ \') # new last line is ' \/' last=' \/' } print -rl$lines last  # JavaScript (ES6), 102 bytes Expects an integer and outputs with the LSB at the bottom left. f=(n,i,p= ,b=n-~n>>i/2)=>b>1?f(n,b/2%2-~i,p+" ")+p+"/ "[b&1|i&1]+s[+!!i]+s+"/ "[b&2|i&1]:p+=s=" \\"  Try it online! ### Commented f = ( // f is a recursive function taking: n, // n = input integer i, // i = counter (initially undefined) p = \n, // p = prefix string b = n - ~n // b = n * 2 + 1 right shifted by floor(i / 2) >> i / 2 // ) => // b > 1 ? // if b is greater than 1: f( // do a recursive call: n, // pass n unchanged b / 2 % 2 // add 2 to i if the bit #1 of b is set - ~i, // or 1 otherwise (*) // (because zeros are twice as large as ones) p + " " // append a space to the prefix string p ) + // end of recursive call p + // append the prefix string p "/ "[ // append a space if: b & 1 | // the target digit is a one i & 1 // or i is odd (grid misalignment) ] + // or a "/" otherwise (the top of a zero) s[+!!i] + // append "\" if i > 0, or a space otherwise // (top segment of previous digit) s + // append " \" (bottom segment of new digit) "/ "[ // append a space if: b & 2 | // the target digit is a one i & 1 // or i is odd (grid misalignment) ] // or a "/" otherwise (the bottom of a zero) : // else (end of recursion): p += // append p s = " \\" // followed by " \" (top segment of MSB)  # APL+WIN, 66 bytes Prompts for bit vector. Index origin = 0 n←(⊂3 2⍴' \ \'),⊂3 3⍴'/\ \ \ \'⋄(-⌽⍳⍴s)⊖(i,i)⍴((i←⍴s)*2)↑n[s←~⎕]  Try it online! Thanks to Dyalog Classic # Perl 5-F, 104 97 bytes @;=(((b=$"x(length($;[0].=" \\".'/'x!$_)-3+$_))."/\\","$b\\".' \\'x!$_)[$_..1],@;)for@F;say for@  Try it online! # Python 3.8 (pre-release), 120 118 bytes def f(i): c=a,=["\n"] while i:c[0]+=" \\"+(x:=~i%2)*"/";c=[a+x*"/"+"\\",x*(a+"\\ \\")]+c;a+=-~x*" ";i//=2 print(*c)  Try it online! Output with a leading newline, some trailing whitespaces at the end of each line and with the least significant bit in the bottom left (LSB) • Nice solution! What does c=a,=["\n"] do? I've never seen that syntax for assignment in Python before. Commented Jul 6 at 17:23 • @noodleperson It is a shorter version of c=["\n"];a="\n" Commented Jul 6 at 22:17 # GolfScript, 828176 75 bytes {49='/\ \ \ \/ \ \ '10/=}%5/zip.3<{' ':a+}%\3>{a\+}%+zip.,.a*:b@*b\+\6+/n*  Try it online! LSB at the bottom left. • Really nice, I was hoping for a GolfScript solution and this is a very cool way of doing it Commented Jul 2 at 10:53 # Pure bash 170 Reading other answers here and re-reading request, there is a version without integer to binary conversion: l=${1//1};t=${#1};printf -vk '%*s'$[t+${#l}-1];p=;for((c=t;c--;)){ ((${1:c:1}))&&echo "$k\$p"&&p=\\||{
k=${k:1};echo "$k/\ $p"$'\n'"$k\ \\";p=\\/;};k=${k:1};};echo \ \\


# Pure bash 204

Full version expecting integer as argument.

for((a=$1;a;a>>=1)){ s=$[a&1]$s;};l=${s//1} t=${#s};printf -vk '%*s'$[t+${#l}-1] p=;for((c=t;c--;)){ ((${s:c:1}))&&echo "$k\$p"&&p=\\||{
k=${k:1};echo "$k/\ $p"$'\n'"$k\ \\";p=\\/;};k=${k:1};};echo \ \\


# JavaScript (Node.js),  130  99 bytes

f=(n,p=
,q=  ,k= \\)=>n?f(n>>1,p+(n&1? :  ),n&1?k:/\\)+p+(n&1?q+k: \${k+k+p+q+k}/):p+q


Try it online!

New contributor
Andrew Bayly is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.