ASCII Borromean Rings

24

2

The Borromean rings are a curious set of three circles, linked such that the removal of any one of them will unlink the other two:

enter image description here

You can make a set for yourself with a couple rubber bands and a binder ring. With more rubber bands, it's easy to make any Brunnian link.

Write a program or function that outputs (prints or returns) this ascii-art representation of Borromean rings:

    +-----+
    |     |
+-----+   |
|   | |   |
| +-|---+ |
| | | | | |
| | +-|---+
| |   | |
+-|---+ |
  |     |
  +-----+

The lines may have trailing spaces and there may be a trailing newline.

The shortest code in bytes wins.

Calvin's Hobbies

Posted 2015-07-20T02:27:05.713

Reputation: 84 000

2I have to say that this is a pretty hard challenge because of how simple the expected output is – Beta Decay – 2015-07-20T05:20:03.887

3I'm a little disappointed. Thought the challenge would be to take an integer size and output rings of that size. – Blacklight Shining – 2015-07-20T13:42:52.400

yeah, I thought so too (program takes int as an input and then draws Brunnian Link with that many components, but that is not unique, maybe a number of crossings?). That kind of program would have to actually do search (or at least trial and error - do these rings interlock and if I remove one, do the go free?) instead of just drawing a fixed picture... – alexey – 2015-07-20T23:36:07.540

Answers

7

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

Optimizer

Posted 2015-07-20T02:27:05.713

Reputation: 25 836

Just curious, where is the newline in your lookup? – Maltysen – 2015-07-20T06:47:19.620

@Maltysen I don't have it. B/N* splits by 11 characters and joins be newline – Optimizer – 2015-07-20T06:48:06.530

that's coooool. – Maltysen – 2015-07-20T06:48:40.003

6

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

Try it here online.

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

Maltysen

Posted 2015-07-20T02:27:05.713

Reputation: 25 023

4

Pyth, 49 bytes

jbc11s@L"+ -|"jC"Tª]UʨWÕÝ_K¨}ÝÝ÷K¨Ý]Òê]UÕ*¡"4

Demonstration.

This uses base 4 encoding, and chops the string into elevenths, then rejoins them on newlines.

isaacg

Posted 2015-07-20T02:27:05.713

Reputation: 39 268

3

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.

Level River St

Posted 2015-07-20T02:27:05.713

Reputation: 22 049

3

Ruby, 117 bytes

Not winning, but I thought it was a cute approach:

puts'    --
    |     |
--  |
|   | |   |
| -||
| | | | | |
| | -|
| |   | |
-||
  |     |
  --'.gsub /-./,'+\0---+ '

Lynn

Posted 2015-07-20T02:27:05.713

Reputation: 55 648

2

BrainFuck, 361 bytes

Here is a little BrainFuck program, only printing char by char.

+++++++++[->>>>++++++++++++++<+++++<+++++<++++<]>----....>--.>.....>-->++++++++++<<<.>>>.<<<<....>>>.<<<.....>>>.>.<<<.>.....<.<...>>>.>.<.<<<...>>>.<<<.>>>.<<<...>>>.>.<.<<<.>.>.>.<...<.<.>>>.>.<.<<<.>>>.<<<.>>>.<<<.>>>.<<<.>>>.<<<.>>>.>.<.<<<.>>>.<<<.>.>.>.<...<.>>>.<.<<<.>>>.<<<...>>>.<<<.>>>.>.<<<.>.>.<...<.<.>>>.>.<<<<..>>>.<<<.....>>>.>.<<<<..>.>.....<.

AboveFire

Posted 2015-07-20T02:27:05.713

Reputation: 623

1

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.
>

M L

Posted 2015-07-20T02:27:05.713

Reputation: 2 865

0

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')

mbomb007

Posted 2015-07-20T02:27:05.713

Reputation: 21 944