17
1
Golfeek is the working name of an esolang I'm occasionally working on. One distinctive feature of this language is that each statement is encoded as a sequence of bits rather than a sequence of bytes.
Instead of just showing a long binary sequence, the 'gutter' of the source editor contains a representation of each statement in a more digest and (slightly) more readable format:
Format
The binary sequence is always read from left to right.
It is first split into nibbles (groups of 4 bits) shown as uppercase hexadecimal between brackets. A space is inserted after each byte, provided that it's followed by another byte or a last lone nibble.
Example:
[1,1,1,1,0,0,0,0,1,0,1,0] --> "[F0 A]" \_____/ \_____/ \_____/
If there are more than 14 nibbles, only the first 6 bytes are shown, followed by a space, followed by
..
, followed by the closing bracket.If the number of bits is not a multiple of 4, the remaining bit(s) is/are appended as '0' or '1' right after the closing bracket.
Example:
[0,1,1,1,1,0,0,1,0,1] --> "[79]01" \_____/ \_____/ \_/
Your task
Given a sequence of bits, return its representation in Golfeek format.
Rules
The sequence of bits may be taken in any reasonable and non-ambiguous format. Please note that the sequence may contain leading zeros, which your format must be able to deal with.
You can assume that there will always be at least 4 bits in the input sequence, and therefore at least one nibble between the brackets.
The output must be a string (or a list of characters) that conforms exactly to the format described above, with uppercase hexadecimal and correct spacing. A trailing linefeed is optional.
This is code-golf.
Test cases
Input
0101
00001
110101
10100111
101001111100
000000000000000
011110101101001110010011000111
11011110101011011011111011101111
11110101000110000001111011001110011100100110111000100000100
111101010001100000011110110011100111001001101110001000001001
1111010100011000000111101100111001110010011011100010000010010
Output
[5]
[0]1
[D]01
[A7]
[A7 C]
[00 0]000
[7A D3 93 1]11
[DE AD BE EF]
[F5 18 1E CE 72 6E 20]100
[F5 18 1E CE 72 6E ..]
[F5 18 1E CE 72 6E ..]0
1
When converting
– Grimmy – 2019-12-19T16:38:41.49310-15
toA-F
,\d\d
can be1\d
to save a byte: TIO.