# Visualise Bit Weaving

The esoteric programming language evil has an interesting operation on byte values which it calls "weaving". It is essentially a permutation of the eight bits of the byte (it doesn't matter which end we start counting from, as the pattern is symmetric):

• Bit 0 is moved to bit 2
• Bit 1 is moved to bit 0
• Bit 2 is moved to bit 4
• Bit 3 is moved to bit 1
• Bit 4 is moved to bit 6
• Bit 5 is moved to bit 3
• Bit 6 is moved to bit 7
• Bit 7 is moved to bit 5

For convenience, here are two other representations of the permutation. As a cycle:

(02467531)


And as a list of pairs of the mapping:

[[0,2], [1,0], [2,4], [3,1], [4,6], [5,3], [6,7], [7,5]]


Your task is to visualise this permutation, using the box-drawing characters ─, │, ┌, ┐, └, ┘, ┼ (Unicode code points: U+2500, U+2502, U+250C, U+2510, U+2514, U+2518, U+253C). This visualisation should satisfy the following constraints:

The first and last line are exactly:

0 1 2 3 4 5 6 7


Between those, you can use as many lines as you want of up to 15 characters each to fit your box drawing characters (you will need at least 4 lines). The lines should start vertically beneath one of the digits on the first row and end vertically above the corresponding digit on the last row. The eight lines must be connected, and may only cross via ┼ (which is always a crossing, never two turning lines which are touching). The exact paths of the lines are up to you (and finding a particularly golfable layout is the core of this challenge). One valid output would be:

0 1 2 3 4 5 6 7
│ │ └─┼┐│ │ └┐│
└─┼─┐ ││└─┼─┐││
┌─┘ │ ││  │ │││
│ ┌─┼─┘│  │ │││
│ │ │ ┌┼──┘ │││
│ │ │ │└┐ ┌─┼┼┘
│ │ │ │ │ │ │└┐
0 1 2 3 4 5 6 7


You may write a program or function and will not take any input. Output the diagram either to STDOUT (or closest alternative) or as a function return value in the form of a string or a list of strings (each representing one line).

Standard rules apply, so the shortest code (in bytes) wins.

• Could we use other symbols for languages that do not support unicode? – flawr Jun 27 '16 at 19:22
• This challenge essentially boils down to copy-pasting the provided output... How about taking a permutation of 01234567 as an input and then connecting that to 01234567 ? So that you have to figure out the links yourself? It would be a significantly more challenging a task, especially for golfing. – shooqie Jun 27 '16 at 19:34
• @shooqie This was discussed in the sandbox. That would indeed be a very different challenge and I'm considering posting that as well at some point. However, I believe there's a lot more to this challenge than copy-pasting the example above. There are countless different admissible outputs and the one above is especially hard to compress whereas others (like the ones used by the existing answers) are much more compressible. The challenge is in finding a single compressible string. That's very different from automatically finding a layout in few bytes. – Martin Ender Jun 27 '16 at 19:50
• Someone has to solve this in evil. – RK. Jun 28 '16 at 5:50
• @Holger There's a good reason we don't do that: then people could just encode the string by packing it in large Unicode characters, which can store several bytes worth of information in a single character. Example. – Martin Ender Jun 29 '16 at 12:44

## Actually, 69 bytes

"│ ┌┘│ │└┐ │└┐└┐""┌┘└┼┐└┼┐ └┼┐└┐""└┼┐│└┐┌┘└┐┌┘│""┌┼─┘"3*"│┌┘"+8r' j;)


Try it online! (the alignment is a little messed up in the online interpreter)

Actually has a HUGE advantage here - all of the box drawing characters are in CP437, so they're only a byte each. Though each character needed could theoretically be encoded in 4 bits (since there are only 9 unique characters), the 31 bytes saved by compressing the string would be lost due to Actually's very poor string processing capabilities. This also means that any 8x4 configuration would result in the same score. Since 8x4 appears to be the (vertically) shortest possible configuration, this is optimal.

Thanks to Martin for 3 bytes!

Thanks to TimmyD for 4 more bytes!

Explanation:

"│ ┌┘│ │└┐ │└┐└┐""┌┘└┼┐└┼┐ └┼┐└┐""└┼┐│└┐┌┘└┐┌┘│""┌┼─┘"3*"│┌┘"+8r' j;)
"│ ┌┘│ │└┐ │└┐└┐""┌┘└┼┐└┼┐ └┼┐└┐""└┼┐│└┐┌┘└┐┌┘│""┌┼─┘"3*"│┌┘"+         push the individual lines, using string multiplication to shorten repeated sections
8r' j   push the string "0 1 2 3 4 5 6 7" (range(8), join on spaces)
;)  make a copy and move it to the bottom of the stack

• Technically a lot of the other answers could have made use of single-byte encodings as well by just using whatever single-byte encoding their language supports (if any), outputting the same bytes as yours and saying "the output is CP437-encoded", but it seems that no one picked up on that. ¯\_(ツ)_/¯ – Martin Ender Jul 18 '16 at 14:43

## PowerShell v2+, 172153148145142131 123 bytes (81 chars)

($a=""+0..7)$b='┌┘'
"│$b$('┌┼─┘'*3)
└┼┐$('│└─┐'*3)$b$('└┼─┐'*3)│ │$($b*6)│"$a


I golfed the weaving further, eliminating the need for several variables by using inline code blocks. This is probably within a few bytes of optimal.

We start by setting $a equal to the range 0..7 that's been joined together with spaces. This is because the default $ofs (Output Field Separator) for an array is a space, so when the array is stringified with ""+ (with an operator like this, PowerShell will try to implicitly cast the right-hand object as the left-hand object), the result is the range space-separated.

AC
BE
DA
C 9
9E 9
9 D
8$E B B B$D9A 9A 9A 9$C9 A9 A9 A9$B┌┼┘$A└┐$9│$80 1 2 3 4 5 6 7  Uses @Marco's output (replace every 16th character with a newline (regex: (.{15}). -> \1\n)). 0 1 2 3 4 5 6 7 └┐│ └┐│ └┐│ └┐│ ┌┼┘ ┌┼┘ ┌┼┘ ┌┼┘ │└┐ │└┐ │└┐ │└┐ │ └┐│ └┐│ └┐│ │ │ ┌┼┘ ┌┼┘ ┌┼┘ │ │ │└┐ │└┐ │└┐ │ 0 1 2 3 4 5 6 7 ## Bash + GNU sed, 140 bytes sed 'h s/$/nxxxacnb b b bnyyycanc xxxcnc b b b cnc yyyc/
:
s/x/ac /
s/y/ca /
s/a/└┐/
s/b/┌┼┘/
t
y/cn/│\n/
G'<<<'0 1 2 3 4 5 6 7'


Output:

0 1 2 3 4 5 6 7
└┐│ └┐│ └┐│ └┐│
┌┼┘ ┌┼┘ ┌┼┘ ┌┼┘
│└┐ │└┐ │└┐ │└┐
│ └┐│ └┐│ └┐│ │
│ ┌┼┘ ┌┼┘ ┌┼┘ │
│ │└┐ │└┐ │└┐ │
0 1 2 3 4 5 6 7


Using @TimmyD's output: 142 bytes

sed 'h
s/$/npbcccnsurdddnbeeepnp bbbbbbp/ : s/b/qt/ s/c/quot/ s/d/psor/ s/e/suor/ t y/nopqrstu/\n─│┌┐└┘┼/ G'<<<'0 1 2 3 4 5 6 7'  Output: 0 1 2 3 4 5 6 7 │┌┘┌┼─┘┌┼─┘┌┼─┘ └┼┐│└─┐│└─┐│└─┐ ┌┘└┼─┐└┼─┐└┼─┐│ │ ┌┘┌┘┌┘┌┘┌┘┌┘│ 0 1 2 3 4 5 6 7  # Tcl, 205 bytes puts "[set B "0 1 2 3 4 5 6 7"] │┌┘ │┌┘ │┌┘ └┐│ └┼┐ └┼─┐└┼──┐││ ┌┘└─┐│ └┐│┌─┼┼┘ │ ┌─┼┘┌─┼┘│ │└┐$B"


Try it online!

outputs

0 1 2 3 4 5 6 7
│┌┘ │┌┘ │┌┘ └┐│
└┼┐ └┼─┐└┼──┐││
┌┘└─┐│ └┐│┌─┼┼┘
│ ┌─┼┘┌─┼┘│ │└┐
0 1 2 3 4 5 6 7


# SOGL V0.12, 64 bytes

└┼─┐³
┘┌┼─┘²
┐│└─┐¹
┌┘┌┘┌┘⁰
│┌²┌┼─²¶└┼¹│└─¹¶┌┘³³³│¶│ ⁰⁰│”8δ@∑Q;O


Try it Here!

Pattern stolen from the powershell