| Bytes | Lang | Time | Link |
|---|---|---|---|
| 114 | JavaScript Node.js | 240808T133059Z | Fhuvi |
| 128 | JavaScript Node.js | 240807T001952Z | Andrew B |
| 043 | Vyxal j | 210528T213650Z | emanresu |
| 271 | brainfuck | 201017T130437Z | RezNesX |
| 079 | Haskell | 201017T142848Z | lynn |
| 031 | Charcoal | 201017T134501Z | Razetime |
| 109 | Staq | 150831T193514Z | M L |
| 139 | Python 3 | 150810T220527Z | mbomb007 |
| 361 | BrainFuck | 150810T174117Z | AboveFir |
| 049 | CJam | 150720T063757Z | Optimize |
| 117 | Ruby | 150720T141455Z | lynn |
| 110 | Ruby | 150720T110622Z | Level Ri |
| 049 | Pyth | 150720T101818Z | isaacg |
| 051 | Pyth | 150720T032730Z | Maltysen |
JavaScript (Node.js), 114 bytes
Replaced reccuring patterns with their identifiers, which are their indexes in the second string after splitting on the #.
_=>`002
001001
201
101101
131
111111
113
11011
31
01001
02`.replace(/./g,e=>` #| #+-----+ #+-|---+ `.split`#`[e])
JavaScript (Node.js), 128 bytes
_=>` +-----+
| |
+-----+ |
| | | |
| +-|---+ |
| | | | | |
| | +-|---+
| | | |
+-|---+ |
| |
+-----+`
When the obvious solution is the best - use it!
Vyxal j, 43 bytes
»⟑|Ḃṗ=›ḟL«w_¬⌊†⁰÷↳ḋ≈∑Ġ«Ṅ⁽ǔ7₇ÞyΠj»`-+| `τ11/
»...» # Base-255 compressed number
`-+| `τ # Decompress using key `-+| `
11/ # Divide into 11 pieces
# join by newlines
brainfuck, 282 280 271 bytes
+++++++++++[>++++>+++>+++++++++++>+<<<<-]>->-....<.++.....--.>>>-.<<....>+++.<.....>.>.<<<.++.....--.>...>.>.<.<...>.<.>.<...>.>[.<]>++.>>.<<...--[.>]+++++[<<.<.>>>-]<<.>.<.<.>.<.<.++.>>.<<...--.>>>.<.<.>.<...>.<.>.>.<<<.++.>>.<<...--[.>]<<<..>.<.....>.>.<<..<.++.....--.
Haskell, 79 bytes
"]O|f]S]S6|g[:[S[VO1g$S)S*)O1f)])61g&S]RZ|x">>=(mapM(:"|\n -")"+++"!!).fromEnum
A base-5 decompression technique. Each ASCII value in the string is used as an index into the list of parts ["+++", "++|", "++\n", ..., "---"] created by mapM.
Approach
See this tip for Cartesian product with mapM.
At first, I used mapM(\_->"......")"123" to create the decoding list, with some permutation of " +-|\n" in place of the dots. The best permutations (yielding the shortest encoded string literals) gave 83-byte solutions:
">:]P>H>F+]%FpHpFob[FrHrFr:vPr>r\bvRfH>F=][">>=(mapM(\_->"\n+ -|")"123"!!).fromEnum
">;|i>C>A1|%AWCWAVwyAXCXAX;ciX>X\tckMC>A=|y">>=(mapM(\_->"\n+ |-")"123"!!).fromEnum
"]R>7]b]_%>+_vbv_tH=_wbw_wRp7w]w\ap:gb]_[>=">>=(mapM(\_->"\n+- |")"123"!!).fromEnum
"|k>7|w|s%>1scwcs`C=sbwbsbkW7b|b\aW;Ow|sy>=">>=(mapM(\_->"\n+-| ")"123"!!).fromEnum
"]T|i]X]U1|+UDXDUBryUCXCUCTJiC]C\tJl5X]U[|y">>=(mapM(\_->"\n+| -")"123"!!).fromEnum
"|l]P|r|n+]1nJrJnGX[nHrHnHlDPH|H\bDT6r|ny][">>=(mapM(\_->"\n+|- ")"123"!!).fromEnum
Each contains one low-ASCII byte, \b or \t or \a.
Then I realized I could write mapM(\_->"\n+ -|")"123" as mapM(:"+ -|")"\n\n\n" to save two bytes. But maybe I could save even more bytes if I used a permutation not starting with \n, because "\n\n\n" is pretty long.
Sadly, the permutations not starting with \n yielded bad values making the string literal longer. The best programs are all still 81 bytes:
">6|g>9>:\24|\f:%9%:#mx:$9$:$61g$>$O1f*9>:<|x">>=(mapM(:"| \n-")"+++"!!).fromEnum
">5]O>9>;\18]\f;%9%;#SZ;$9$;$5+O$>$g+M/9>;<]Z">>=(mapM(:"| -\n")"+++"!!).fromEnum
"|f>5|m|l\f>\24l1m1l-9<l.m.l.f%5.|.M%6,m|lx><">>=(mapM(:"|-\n ")"+++"!!).fromEnum
"]M>6]S]T\f>\18T+S+T(9<T)S)T)M%6)])f%50S]TZ><">>=(mapM(:"|- \n")"+++"!!).fromEnum
However, I had another trick up my sleeve: the problem statement allows for trailing spaces on each line, and maybe I could insert 3 trailing spaces in such a way that the string literal becomes one "actual character" longer, but ends up not having stuff like \24 and \f in it.
So I ran a brute force search for all positions to add such trailing spaces. And indeed, adding a trailing space on lines 2, 4, and 6 lets us write the above 79-byte program, where the encoded string is fully printable ASCII.
There are many other permutation-space-placement pairs that tie this one. Here are just a few:
"]O|f]S]SU|x]$])]$O1g$S)S*)O1f)])61g&S]RZ|x" (44,"+|\n -",[1,1,5])
"|g]M|m|m5]Oyz1m1k-SZk.m.k.g+M.|.5+O'm|kx]Z" (44,"+|\n- ",[1,2,2])
">6|fW=>=A|x>)>$>)61f&$9$:$61g$>$O1f*9>:<|x" (44,"+| \n-",[0,1,4])
">5]Mp=>=g]M=G>$>.5+M.9$9'$5+O$>$g+M/9>;<]Z" (44,"+| -\n",[0,2,5])
"|f>5|m|ms><|)|.|)f%60.m.l.f%5.|.M%6,m|lx><" (44,"+|-\n ",[1,1,4])
"]M>5b]+]-><],+S+T(9<T)S)T)M%6)])f%50S]TZ><" (44,"+|- \n",[0,0,2])
I tried a few other things
I tried a few other things. If you pad each line in the target string to "11 characters followed by a newline", then the newlines will only occur at indices ≡ 3 mod 4. In fact, if you look at each k mod 4 and count the unique characters there, they group themselves quite nicely:
target!!k `elem` " +-|" when k ≡ 0 mod 4.
target!!k `elem` " -" when k ≡ 1 mod 4.
target!!k `elem` " +-|" when k ≡ 2 mod 4.
target!!k `elem` " -\n" when k ≡ 3 mod 4.
So a mixed-base approach is tempting.
Of course, something like mapM id[" +-|"," -"," +-|"," -\n"] is too long, but I played with mapM(`drop`"+|\n- ")[0,3,0,2]. Sadly, the strings just aren't great. The best I could get out of this was 93 bytes.
"³F{³;¥F}¥;/¥1(K//-/={/§9=}9§³9©\130W">>=(mapM(`drop`"||+\n- ")[0,4,1,3]!!).fromEnum
Alternatively, you could try a base-4 approach with different alphabets for each k mod 4. This is easy to express with mapM. I got this 84 byte solution, which would be 70 bytes if Haskell programs used some ANSI encoding rather than UTF-8.
"ÿJ¤ÿ?ðJ§ð?3ð6*p3303B¤3ó<B§<óÿ<öª|">>=(mapM(:"+- ")"|-|\n"!!).fromEnum
Charcoal, 31 bytes
B⁷¦⁷M±⁴¦²B⁷¦⁷M²¦²B⁷¦⁷M²→|M³¦²¦¹
Link is to verbose version of code.
It's pretty fun to have a box function.
Basically draws three boxes at the required location, and patches the required places.
Staq, 109 chars
&iiiqi{1" "}{211}{c"| "}{fcc}{o"+-|"}{p"+--"}{r"---+"}{ec;}22pr;22c22epr21ec2f2ecor1effcefor;f2ceor1e2c22e2pr
output:
Executing D:\codegolf\Staq borromean rings.txt
+-----+
| |
+-----+ |
| | | |
| +-|---+ |
| | | | | |
| | +-|---+
| | | |
+-|---+ |
| |
+-----+
Execution complete.
>
Python 3, 139 bytes
This is the closest I can get to printing it directly (which would be 134 bytes) without actually doing so.... I'm not sure how to shorten it any more.
a='+-----+'
b='+-|---+'
c=' '*4
d='| '
e=c+d
print(c+a,e*2,a+e[1:],"| | "*2,d+b+" |",d*6,d+d+b,"| | "*2,b+" |",e[2:]+e," "+a,sep='\n')
BrainFuck, 361 bytes
Here is a little BrainFuck program, only printing char by char.
+++++++++[->>>>++++++++++++++<+++++<+++++<++++<]>----....>--.>.....>-->++++++++++<<<.>>>.<<<<....>>>.<<<.....>>>.>.<<<.>.....<.<...>>>.>.<.<<<...>>>.<<<.>>>.<<<...>>>.>.<.<<<.>.>.>.<...<.<.>>>.>.<.<<<.>>>.<<<.>>>.<<<.>>>.<<<.>>>.<<<.>>>.>.<.<<<.>>>.<<<.>.>.>.<...<.>>>.<.<<<.>>>.<<<...>>>.<<<.>>>.>.<<<.>.>.<...<.<.>>>.>.<<<<..>>>.<<<.....>>>.>.<<<<..>.>.....<.
CJam, 53 51 50 49 bytes
Plain old base conversion...
"FÓîÞ¤ÛYËB[¢O²êÍÓ
}²|äG"299b4b"+ -|"f=B/N*
All characters are well in extended ASCII range (ASCII code 1 to 255), so number of characters == number of bytes.
Try it online here and get the original code here
Ruby, 117 bytes
Not winning, but I thought it was a cute approach:
puts' --
| |
-- |
| | | |
| -||
| | | | | |
| | -|
| | | |
-||
| |
--'.gsub /-./,'+\0---+ '
Ruby, 110
-2.upto(8){|i|s=" "*(i%6)+"+-----+"*(1-i%2)+" "*9
6.times{|j|"@d me?K[RR@"[i+2].ord>>j&1>0&&s[j*2]=?|}
puts s}
Something different from straight base conversion.
Ungolfed:
-2.upto(8){|i| #for each line
s=" "*(i%6)+"+-----+"*(1-i%2)+" "*9 #load s with "+-----+" (if required!) padded appropriately with leading spaces and with nine trailing spaces.
6.times{|j|"@d me?K[RR@"[i+2].ord>>j&1>0&&s[j*2]=?|} #replace characters with | as necessary, according to the 6-bit number encoded by each character in the magic string.
puts s} #print the line.
Pyth, 49 bytes
jbc11s@L"+ -|"jC"Tª]UʨWÕÝ_K¨}ÝÝ÷K¨Ý]Òê]UÕ*¡"4
This uses base 4 encoding, and chops the string into elevenths, then rejoins them on newlines.
Pyth - 51 bytes
I'm sure someone's gonna beat this quick, but just a base compression answer cuz I'm feeling lazy. I'll try to write a serious answer soon.
s@L"
+-|"jC" zB²;¶Ê ¿ïÁ»#-ÌClHõy%|ap"5
s Reduce on string concatenation
@L Map second arg to index first arg
"..." String of all chars (Pyth allows literal newlines)
j Base conversion to list
C Base conversion 256 -> 10
"..." Base 256 string
5 To Base 5