(with apologies to Jim West for the title, and randomly inspired by Cisco's textual representation of their logo: .:|:.:|:.
for the concept)
Given an input integer 1 <= n <= 255
, output an ASCII art representation of a suspension bridge of distance n
following the below construction rules:
- The start and end of the bridge (not counted in the
n
distance) are always-|
and|-
, so the bridge can appropriately connect to the highways next to it. - The bridge doesn't extend downward (the roadway level, composed of the
-
row, is the bottom row). - There can be at most two roadway pieces
--
in a row, any longer span requires suspension cables for support. - The suspension cables
\
extend from the roadway up to the towers|
in straight lines. - The towers
|
must be tall enough to support the adjacent suspension cables, but no taller. - The bridge must be balanced left-to-right about the middle point, favoring the center sections whenever possible.
- All of the above should result in a minimization of the cables, but just to be clear, the number of suspension cables must be minimized while still following the above rules.
To provide a visual representation, here are the expected outputs for n = 1, 2, 3, ... 15
--
1
-|-|-
2
-|--|-
3
-|\-/|-
4
-|\--/|-
5
|\ /|
-|-\-/-|-
6
|\ /|
-|-\--/-|-
7
|\ /|
| \ / |
-|--\-/--|-
8
|\ /|
| \ / |
-|--\--/--|-
9
|\ /|
| \ / |
| \ / |
-|\--\-/--/|-
10
|\ /|
| \ / |
| \ / |
-|\--\--/--/|-
11
|\ /|
| \ / |
| \ / |
|\ \ / /|
-|-\--\-/--/-|-
12
|\ /|
| \ / |
| \ / |
|\ \ / /|
-|-\--\--/--/-|-
13
|\ /|
| \ / |
| \ / |
|\ \ / /|
| \ \ / / |
-|--\--\-/--/--|-
14
|\ /|
| \ / |
| \ / |
|\ \ / /|
| \ \ / / |
-|--\--\--/--/--|-
15
|\ /|
| \ / |
| \ / |
|\ \ / /|
| \ \ / / |
| \ \ / / |
-|\--\--\-/--/--/|-
Input
A single positive integer in any convenient format, n > 9
.
Output
The ASCII-art bridge following the above construction technique.
Rules
- Leading or trailing newlines or whitespace are all optional, so long as the bridge characters themselves line up correctly.
- Either a full program or a function are acceptable. If a function, you can return the output rather than printing it.
- If possible, please include a link to an online testing environment so people can try out your code!
- Standard loopholes are forbidden.
- This is code-golf so all usual golfing rules apply, and the shortest code (in bytes) wins.