# Building a Bridge

Your task is to build a bridge to connect two cliffs given an input d, the distance apart. d will always be even

However, the bridge needs columns to hold it up. Each column can hold a max of 6 spaces on each side.

For this example:

________                        ________
|                      |
A    |                      |   B

|----------------------|
d = 22


The bridge for d = 20should look like this with two columns. Columns do not count in d.

_____|__________|_____
12345|1234554321|12345
|          |


Rules:

1. Must have enough columns to stand up.

2. Must have minimum number of columns needed to stand up.

3. Must be symmetrical

4. Lowest amount of Bytes Wins

Examples: (#s are only to help you count spaces. Should not be included in your output)

d = 10

_____|_____
12345|12345
|


d = 32

_____|___________|___________|_____
12345|12345654321|           |
|           |           |


d = 8

____|____
1234|1234
|


d = 4

__|__
12|34
|


d = 22

_____|____________|_____
12345|123456654321|
|            |


or

______|__________|______
123456|1234554321|123456
|          |

• To clarify, are the numbers in the output required, or merely illustrative? May 4, 2016 at 19:28
• @isaacg No they are not needed in the output. They are just there so you guys dont have to count lines on my examples. May 4, 2016 at 19:34
• I think your specification is flawed? What prevents a 1|2|3|4|5...|d solution where | is a beam.
– Vlo
May 4, 2016 at 19:42
• @Vlo One of the rules is to use the minimum number of columns possible. Therefore using a column every space would not be the minimum. May 4, 2016 at 19:44
• You say d is always going to be even, but in your last example, d=21. May 4, 2016 at 20:24

## JavaScript (ES6), 92 bytes

d=>[..."_  "].map(c=>(s=c+c[r='repeat'](n%6))+'|'+(c[r](12)+'|')[r](n/6)+s,n=d-1>>1).join\n


Where \n represents the literal newline character. If d can be odd, it takes me 128 bytes:

d=>[..."_  "].map(c=>[...Array(d+1)].map((_,i)=>(d&1?i&&d-i&&(i>m)+5+i-m:((d-1)%24>11)*6+i-m)%12?'':'|',m=d>>1).join(c)).join\n

• How can your solution for odd numbers work? For d=35, none of the optimal solutions are symetrical. May 4, 2016 at 20:58
• @Hohmannfan It returns the least suboptimal symmetrical solution, which in this case is |____________|___________|____________| etc.
– Neil
May 4, 2016 at 21:12
• I guess that is the best interpretation. May 4, 2016 at 21:18

# Ruby, 108 bytes

Probably can be golfed down a lot more. Greedy algorithm.

->d{s='',k=6
(s+=?_*[d,k].min+(d>k/2??|:'');d-=k;k=12)while d>0
s=s.chomp(?|)+s.reverse+\$/
s+s.tr(?_,' ')*2}