# Fill the Golfeek gutter

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"
\_____/ \_____/ \_/


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 .

## 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
[F5 18 1E CE 72 6E 20]100
[F5 18 1E CE 72 6E ..]
[F5 18 1E CE 72 6E ..]0


# 05AB1E, 363433 31 bytes

Ć4ô¤¨s¨Ch2ôJDg8@i6∍„..ª}ðý"[ÿ]ÿ


Try it online!

s4µLÐṀ©s14Ḅ‘ịØHUḢaȧ⁾..$ƊUs2KØ[j;ḟ®F  A full program which, given a list format of 1s and 0s, prints the result. Try it online! Or see the test-suite. # Retina 0.8.2, 112 111 bytes .{4}$&
(.+)
[$1] TdL.*] B AB +BA ABB A+(B*)$.1
TdL1\d(?=.*])
B(.)
$1 T _\w.. (\[.{18})...+]$1..]


Try it online! Link includes test cases. Edit: Saved 1 byte thanks to @Grimmy. Explanation:

.{4}
$&  Group the nibbles. (.+) [$1]


Bracket the nibbles.

TdL.*]


Change the bits used by the nibbles from 01 to AB to distinguish them from the spare bits.

B
AB
+BA
ABB


Convert from binary to unary.

A+(B*)
$.1  Convert from unary to decimal. TdL1\d(?=.*]) B(.)$1


Convert 10-15 from decimal to hexadecimal.

T _\w..


Group pairs of nibbles into bytes.

(\[.{18})...+]

# Japt, 50 bytes

ò4
jJUÌÊ¦4
®n2G uÃò mq
"[]"i1WjT7 ¸h18WÊ?"..":P)+V


Try it

ò4            (Input as a string) partitioned on each 4 bits.

jJ             V = get n elements from last index and remove them
UÌÊ¦4        n = is last element length != 4 ?

®n2G uÃò mq           Convert each nibble to base 16,
uÃ        to uppercase,
ò mq    and join each pair.

"[]"i1         Inserts between squares :
WjT7      first 7 elements(removing them),
¸    joined with space.
h18             Then replace characters at index 18 with :
WÊ?".."       '..' if not empty
:P     else empty string.
)+V           Finally appends remaining bits and outputs implicitly.


# C (gcc), 194181191 190 bytes

Thanks to ceilingcat (-14 bytes) for the suggestions. Fixed an edge case (+10 bytes).

The function takes the input string and builds up byte-sized representations a nibble at a time, outputting the results until the sixth byte, and changing the [ to a space after the first byte output (if there is one). The buffer is reset after each output.

After the sixth byte, nothing is output until the entire string is processed, but if the length exceeds 59 bytes (7 bytes + 3 bits), the stored representation changes to .., which is then output at the end. Excess bits that don't fit in a nibble are printed from the end of the input string. There is an edge case that I had to specifically check for, which is an input between 49 and 51 bytes (6 bytes + 3 bits), as an extra space would normally get printed before the ending bracket.

c,t;f(char*s){char u[4]="[";for(t=c=0;*s;c++>58?u[1]=u[2]=46:0)t+=t+*s++-48,c%4>2?u[c%8/4+1]=t+48+7*(t>9),t=0:0,c%8>6&c<48?printf(u),*(int*)u=32:0;printf("%s]%s",u+(c%8<1|c-48U<4),s---c%4);}


Try it online!

# Burlesque, 48 bytes

4co{L[4.<}ptl_FLjb2b62co)++sa7.>{6.+".."[+}if+]Q


Try it online!

4co       #Split into nibbles
{L[4.<}pt #Partition into those whose lengths >4 and those <4
l_FL      #Take the remainder as a flat list
jb2b6     #Convert the main block into base 16 (via binary)
2co)++    #Join as pairs
sa7.>     #Length greater than 7
{
6.+      #Take first 6 discarding remainder
".."[+   #Append ".."
}if       #If length > 6
+]        #Append remainder bits
Q         #Prettify

• @Arnauld Ah, thanks. I just missed that. – DeathIncarnate Jan 16 '20 at 15:55