# Binary Branches

Given a binary number, your task is to create a 'branch' of that number, with a depth of 2.

For example, given 0 as input, you should output exactly this:

     /000
/00
/   \001
0
\   /010
\01
\011


This should be fairly self explanatory of how the branches should be created. Depth 2 means we calculate branches for numbers of up to 2 numbers longer. We also calculate the branches in order, with zeroes at the top and ones at the bottom.

More test cases:

0

/000
/00
/   \001
0
\   /010
\01
\011

1

/100
/10
/   \101
1
\   /110
\11
\111

00

/0000
/000
/    \0001
00
\    /0010
\001
\0011

01

/0100
/010
/    \0101
01
\    /0110
\011
\0111

10

/1000
/100
/    \1001
10
\    /1010
\101
\1011

11

/1100
/110
/    \1101
11
\    /1110
\111
\1111


### Rules

• You will never receive characters in the input other than 1 and 0.
• 0 < length of input < 11.
• Trailing whitespace allowed at the end of lines.
• 0 < length of input < 11 is 11 decimal or binary? :P – ETHproductions Apr 11 '17 at 0:33
• @ETHproductions Decimal :P – Okx Apr 11 '17 at 10:08

# Jelly, 39 38 bytes

L⁶ẋ,W;“/0¶\1 ”ṃ@“ð&ẏ{×ẏĊfẏȷ®ỤṪ⁻ʠaƇGⱮȷ’


Try it online!

### How?

The art to be printed is:

L  L /N00
L /N0
L/ L \N01
N
L\ L /N10
L \N1
L  L \N11


Where N is the input string and L is a string of spaces of the length of the input string.

As such it is comprised of eight components (L, N, /, 0, the newline character, \, 1, and the space character) and hence may be stored as a base-8 number ( which may be compressed as a base-250 number in Jelly). The ṃ atom combines base conversion and indexing into a list (effectively one may define arbitrary digits to be used).

L⁶ẋ,W;“/0¶\1 ”ṃ@“ð&ẏ{×ẏĊfẏȷ®ỤṪ⁻ʠaƇGⱮȷ’ - Main link: binary string s  e.g. "100"
⁶                                     - space character
ẋ                                    - repeat by:
L                                      -     length(s)                    [' ',' ',' ']
W                                  - wrap s in a list                 [['1','0','0']]
,                                   - pair               [[' ',' ',' '],['1','0','0']]
“/0¶\1 ”                         - char list: ['/','0',<newline>,'\',','1',' ']

;                                 - concatenate        [[' ',' ',' '],['1','0','0'],'/','0',<newline>,'\',','1',' ']
“ð&ẏ{×ẏĊfẏȷ®ỤṪ⁻ʠaƇGⱮȷ’ - base 250 number: 91531517467460683226372755994113932025707662527
ṃ@                       - base decompression [reversed @arguments]
-     this uses the concatenated list above as
-     the 8 digits of that number in base 8.
- implicit print


## Batch, 178170 159 bytes

@set/pb=
@set s=%b:0= %
@set s=%s:1= %
@set e=@echo %s%
%e%  %s% /%b%00
%e% /%b%0
%e%/ %s% \%b%01
@echo %b%
%e%\ %s% /%b%10
%e% \%b%1
%e%  %s% \%b%11


Edit: Saved 11 bytes thanks to @ConorO'Brien.

• I only count 149 bytes. – Engineer Toast Apr 10 '17 at 16:02
• I assume Neil is counting line breaks as the Windows-style CRLF whereas TIO is counting them as LF. I'm not sure whether LF works for Batch on Windows. – Alex A. Apr 11 '17 at 3:23

## JavaScript (ES6), 112 bytes

s=>22   /300
2 /30
2/2  4301
3
242  /310
2 431
22   4311.replace(/./g,n=>[s.replace(/./g,' '),s,'\\'][n-2]||n)


### Demo

let f =

s=>22   /300
2 /30
2/2  4301
3
242  /310
2 431
22   4311.replace(/./g,n=>[s.replace(/./g,' '),s,'\\'][n-2]||n)

console.log(f('0'))
console.log(f('11'))
console.log(f('101'))

• why not [n,n,s.replace(/./g,' '),s,'\\'][n]? – tsh Apr 10 '17 at 3:01
• @tsh That would require to search for /\d/g rather than /./g to ignore non-numeric characters. – Arnauld Apr 10 '17 at 8:35

# Python 3, 117 109 bytes

lambda k:'ll   /g00\nl /g0\nl/l  \g01\ng\nl\l  /g10\nl \g1\nll   \g11'.replace('l',' '*len(k)).replace('g',k)


Try it online!

The format string when printed looks like:

ll   /g00
l /g0
l/l  \g01
g
l\l  /g10
l \g1
ll   \g11


This looks good already for string of length of 1. All we got to do is replace l by spaces of length equal to that of g and, of course, g is to be replaced by the original string

• You can save a byte using an unnamed lambda, which also means you can get rid of the print (since returning the string should be acceptable) and save another seven bytes. You can then save two more by using a multiline string getting you down to 107... TIO – Jonathan Allan Apr 10 '17 at 16:23

# Python 3.6, 172153 128 bytes

Literally does not get more straightforward than this... This is actually shorter than my original attempt at generating it with an algorithm. How sad.

k=input()
l=len(k)
b=' '*l
print(f'{b*2}   /{k}00\n{b} /{k}0\n{b}/ {b}\\{k}01\n{k}\n{b}\\ {b}/{k}10\n{b} \\{k}1\n{b*2} \\{k}01')


-19 bytes thanks to @Leo
-25 bytes thanks to @L3viathan

• I think it would be shorter to drop a, c, and d, and use only b and spaces in the final string. (a is b*2+' ') – Leo Apr 10 '17 at 5:17
• Weird, still seems 172 bytes for me. – programmer5000 Apr 10 '17 at 17:50
• @programmer5000 Sorry, that would be because I forgot to update the code itself. – HyperNeutrino Apr 10 '17 at 19:29
• Save 26 characters with format strings: print(f'{a}/{k}00\n{b} /{k}0\n{b}/ {b}\\{k}01\n{k}\n{b}\\ {b}/{k}10\n{b} \\{k}1\n{b*2} \\{k}01') – L3viathan Apr 11 '17 at 13:50
• @L3viathan Can you check the syntax on that? It's giving me a syntax error. – HyperNeutrino Apr 11 '17 at 13:53

# C, 170 168 bytes

Thanks to @Neil for saving two bytes!

n;f(char*s){n=strlen(s);printf("%*c%s00\n%*c%s0\n %*c%*c%s01\n%s\n %*c%*c%s10\n%*c%s1\n%*c%s11",2*n+4,47,s,n+2,47,s,n,47,n+3,92,s,s,n,92,n+3,47,s,n+2,92,s,2*n+4,92,s);}


Try it online!

• Rather than printing a / or  padded to width n+1, why not print a space, and then a / or \ padded to width n? – Neil Apr 9 '17 at 21:41
• Ugh, let me try that again. Rather than printing a / or \ padded to width n+1, why not print a space, and then a / or \ padded to width n? – Neil Apr 10 '17 at 8:13

# Python 3, 96 bytes

lambda s:"""   /00
 /0
/  \01

\  /10
 \1
   \11""".translate([s,' '*len(s),s])


Try it online! The unprintable characters do not display correctly; the string format is the same as officialaimm's, but with \x01 for l and \x02 for g.

ll   /g00
l /g0
l/l  \g01
g
l\l  /g10
l \g1
ll   \g11


Uses string substitution with Python 3's flexible translate. The translate list [s,' '*len(s),s] maps \x01 to ' '*len(s) and \x02 to s. Any larger characters are unchanged because they give indices that are out-of-bounds for the list. \x00 could not be used because a null byte is read as a program end, so the first entry is wasted.

# PHP, 128 bytes

Only a simple Output

<?=$b=str_pad("",strlen($a=$argn)),"$b   /{$a}00\n$b /{$a}0\n$b/$b \\{$a}01\n$a\n$b\\$b /{$a}10\n$b \\{$a}1\n$b$b   \\{$a}11";  Try it online! # Stacked, 81 bytes {!n#'' '*@s's s /n00 s /n0 s/ s \n01 n s\ s /n10 s \n1 s s \n11' '\l'$#~1/repl}


Try it online!

Not very interesting, unfortunately. Here's the most interesting part:

'\l'$#~1/repl repl replace all '\l' letters$#~           by evaluating
1/         over one argument (otherwise, it would evaluate the "last" thingy)


This is basically string interpolating, but 10 bytes shorter than the builtin.

# ///, 116 bytes

/[/\\\///x///*/[y\\0[ y\/\/y\\1[ y\//**********/y///s/yx//~/  /~ ss[x00
s[x0
s[~s\\x01
x
s\\~s[x10
s\\x1
~ ss\\x11


Try it online!

Input is as follows:

/[/\\\///x/INPUT HERE!!!!!!!!//*/[y\\0[ y\/\/y\\1[ y\//**********/y///s/yx//~/  /~ ss[x00
s[x0
s[~s\\x01
x
s\\~s[x10
s\\x1
~ ss\\x11


Works by using a basic template, and adding spaces and characters where needed.

The byte count went up because Ørjan Johansen realized that it did not handle spacing at first. But the problem is know fixed.

• I gave you an upvote before checking that it worked - but you're not adjusting the spacing for length. I don't see a succinct way to do that with such a literal input format. – Ørjan Johansen Apr 10 '17 at 23:33
• Or wait, it's not totally hopeless since there's an input length limit of 11. – Ørjan Johansen Apr 10 '17 at 23:38
• Something like /*/\/y0\/ y\/\/y1\/ y\//**********/y///s/yx/ and then you get spacing with s. – Ørjan Johansen Apr 10 '17 at 23:44
• @ØrjanJohansen Oops, forgot about spacing... thanks. How would I incorporate your code into the answer? – Comrade SparklePony Apr 11 '17 at 0:00
• FWIW /00/0|0//01/0|1//10/1|0//11/1|1//|/<\\y>//z/<y>x//<y>0/ //<y>1/ //<\\y\>///s/z/ can handle arbitrary length. – Ørjan Johansen Apr 11 '17 at 0:01

# Python 2, 101,91 bytes113 bytes

lambda y:'   ++/_00\n +/_0\n+/  +\\_01\n_\n+\\  +/_10\n +\\_1\n   ++\\_11'.replace('_',y).replace('+',' '*len(y))


Try it online!

Input is a string of 0's and 1's of length 1 or 2! That is 0,01,10 or 11!

+12 bytes - corrected the spacing in \ for length two input.

• your output does not adjust as per the length of the string. – officialaimm Apr 10 '17 at 7:58
• ...and the question specifies "0 < length of input < 11". – Jonathan Allan Apr 10 '17 at 16:53
• @officialaimm oh yeah. Just noticed. Thanks. Will update my answer! Jonathan.. that was a typo. Thanks I corrected it. – Keerthana Prabhakaran Apr 10 '17 at 17:37

# Charcoal, 34 bytes

Ｐ<³←⮌θＦ²«Ｊ³⁻×⁴ι²θＰ<²Ｉι↗Ｆ²«Ｐ⁺⁺θικ↓↓


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

Ｐ<³


Print the left pairs of /s and \s.

←⮌θ


Print the input right-justified at the current position.

Ｆ²«


Loop through the branches.

Ｊ³⁻×⁴ι²


Move the the position of the branch. We can do this because the root was printed right-justified so that the middle branch is always at the same absolute position.

θ


Print the input.

Ｐ<²


Print the right pair of / and \.

Ｉι


Print the branch suffix.

↗


Move to the first leaf.

Ｆ²«


Loop through the leaves.

Ｐ⁺⁺θικ


Print the input and the branch and leaf suffix.

↓↓


Move to the next leaf. Note: If trailing whitespace was acceptable then Ｆ²⁺⁺⁺θικ¶¶ would save a byte.