33
6
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
However, any other layout that correctly connects the right digits is fine too. Please show your chosen output in your answer.
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 code-golf rules apply, so the shortest code (in bytes) wins.
This is strangely reminiscent of the utility graph... – Conor O'Brien – 2016-06-27T17:49:56.837
1Could we use other symbols for languages that do not support unicode? – flawr – 2016-06-27T19:22:28.500
3This challenge essentially boils down to copy-pasting the provided output... How about taking a permutation of
01234567
as an input and then connecting that to01234567
? So that you have to figure out the links yourself? It would be a significantly more challenging a task, especially for golfing. – shooqie – 2016-06-27T19:34:47.0535@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 – 2016-06-27T19:50:58.377
2Someone has to solve this in evil. – RK. – 2016-06-28T05:50:45.250
It should be allowed to write a string or a string array expression. In Haskell there's no such thing as no-argument functions, though you can write a function that takes a void-typed argument
()
. – John Dvorak – 2016-06-28T08:02:46.5571@JanDvorak Printing string/array literals seems rather unclean. A void-typed function returning the string(s) would be fine though. – Martin Ender – 2016-06-28T08:12:40.607
How about a function that ignores its argument, then? – John Dvorak – 2016-06-28T08:29:30.317
1@JanDvorak I think I'm fine with that too. Might be worth asking on meta for a general rule though. – Martin Ender – 2016-06-28T08:30:20.500
@JanDvorak Relevant meta post
– Mego – 2016-06-29T08:12:43.027Great. The top voted answer so far has 131 bytes of program code to produce 95 bytes of constant output. Granted it has found a more compact output, but still proves @shooqie right as a program printing a constant string containing that output is shorter… or well, it depends on the chosen character encoding, of course. – Holger – 2016-06-29T12:27:46.730
1@Holger Just because it has the most votes doesn't mean it's the shortest. Also, unless your language can use a code page that has all the required characters in a single byte, the output is well over 200 bytes. I admit that this encoding discrepancy is a bit unfortunate, but if you ignore it, then even the PowerShell answer is shorter than its output. – Martin Ender – 2016-06-29T12:32:44.573
1Maybe counting characters would be better… – Holger – 2016-06-29T12:42:09.683
3
@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 – 2016-06-29T12:44:31.153I just noticed that I should have said code points rather than characters, but anyway, any kind of packing or compressing requires code for extracting which doesn’t differ to the situation we have with the bytes here. I don’t consider the character examples less readable than the examples here… – Holger – 2016-06-29T12:54:53.350
@Holger It's not about readability but about interesting approaches. In some of the golfing languages, Unicode packing is trivial and doesn't cost a lot of characters at all. (Also I don't see what the difference between characters and code points is for the purpose of the counting.) – Martin Ender – 2016-06-29T13:00:01.847
U+0041U+0302U+0333
are three code points, but only one character,Â̳
… – Holger – 2016-06-29T13:27:46.487@Holger Oh right, I believe we normally consider combining marks "characters" as far as counting is concerned. But yeah, that would make things even worse. – Martin Ender – 2016-06-29T13:28:49.207
1@flawr Sorry, I never saw your comment. In most languages you should be able to output a simple byte stream. There are single-byte code pages, like CP437 which contain all of the necessary characters. That means if you just output those bytes and interpret your output as CP437 (or some other suitable codepage), you'd still have a valid answer without having to worry about Unicode. – Martin Ender – 2016-06-30T07:16:47.400
Is my answering proposal valid? https://tio.run/##K0nO@f@/oLSkWEFJIbo4tUTBScHA0MjYxNTMPJbr0ZSeR1P2PJoy49GUJiQ0BSw4gQvGhyuCSkDEFRQUuFA1NcDlIIgL2TRMu0DSCqg2I5QAJaeoOAHZSlz//wMA
– sergiol – 2017-07-23T12:04:53.667@sergiol Interesting, but no. – Martin Ender – 2017-07-23T12:28:06.387