10
\$\begingroup\$

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
      |          |
\$\endgroup\$
  • \$\begingroup\$ To clarify, are the numbers in the output required, or merely illustrative? \$\endgroup\$ – isaacg May 4 '16 at 19:28
  • \$\begingroup\$ @isaacg No they are not needed in the output. They are just there so you guys dont have to count lines on my examples. \$\endgroup\$ – JoshK May 4 '16 at 19:34
  • \$\begingroup\$ I think your specification is flawed? What prevents a 1|2|3|4|5...|d solution where | is a beam. \$\endgroup\$ – Vlo May 4 '16 at 19:42
  • \$\begingroup\$ @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. \$\endgroup\$ – JoshK May 4 '16 at 19:44
  • \$\begingroup\$ You say d is always going to be even, but in your last example, d=21. \$\endgroup\$ – SE - stop firing the good guys May 4 '16 at 20:24
4
\$\begingroup\$

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`
| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ How can your solution for odd numbers work? For d=35, none of the optimal solutions are symetrical. \$\endgroup\$ – SE - stop firing the good guys May 4 '16 at 20:58
  • \$\begingroup\$ @Hohmannfan It returns the least suboptimal symmetrical solution, which in this case is |____________|___________|____________| etc. \$\endgroup\$ – Neil May 4 '16 at 21:12
  • \$\begingroup\$ I guess that is the best interpretation. \$\endgroup\$ – SE - stop firing the good guys May 4 '16 at 21:18
0
\$\begingroup\$

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}
| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.