20
5
Imagine the following diagrams as sets of vertical criss-crossing tubes.
1 2 1 2 1 2 3 4
\ / \ / \ / \ /
X | | |
/ \ / \ / \ / \
2 1 1 2 | X |
\ / \ /
X X
/ \ / \
3 1 4 2
In the leftmost diagram, the 1
and 2
slide down their respective slashes, cross at the X
, and come out at opposite sides from where they started.
It's the same idea in the middle diagram, but the |
signifies that the paths do not cross, so nothing changes.
The rightmost diagram shows a more complex tube routing that permutes 1 2 3 4
into 3 1 4 2
.
Goal
Your goal in this code golf challenge is to draw these "tube routing diagrams" given a permutation such as 3 1 4 2
. The shortest program in bytes will win.
Details
- Input comes from stdin as any permutation of the numbers from 1 to n separated by spaces, where n is a positive integer. You may assume all input is well formed.
The routing diagram output goes to stdout.
- "Dropping" the numbers 1 through n in order into the top of the diagram should result in the input permutation coming out at the bottom. (Top and bottom are always layers of slashes.)
- The diagram does not need to be optimally small. It may be as many levels as necessary as long as it is correct.
- The diagram should only contain the characters
\/ X|
as well as newlines (no numbers). |
should always be used on the outermost intersections since usingX
wouldn't make sense.- A few leading or trailing spaces is fine as long as the diagram is all lined up correctly.
Examples
An input of 3 1 4 2
might produce (same as above)
\ / \ /
| |
/ \ / \
| X |
\ / \ /
X X
/ \ / \
An input of 1
might produce
\
|
/
|
\
|
/
An input of 3 2 1
might produce
\ / \
X |
/ \ /
| X
\ / \
X |
/ \ /
An input of 2 1 3 4 6 5
might produce
\ / \ / \ /
X | X
/ \ / \ / \
4Great question! I can't believe it's only been two weeks that you joined -- you seem to be everywhere. – xnor – 2014-07-21T23:58:45.960
@xnor :D Thanks a bunch. But really I've been spending too much time here... – Calvin's Hobbies – 2014-07-22T00:00:56.467
Can an
X
connect directly to a|
the way a/
does? To anotherX
? – xnor – 2014-07-22T00:17:05.0401@xnor No. It should always be in the
row of slashes
,row of X's and |'s
,row of slashes
,row of X's and |'s
, ... format. – Calvin's Hobbies – 2014-07-22T00:20:17.557Can
n
be larger than 10? – Οurous – 2014-07-23T07:32:01.860@Ourous Yes. n can be arbitrarily large (to a reasonable amount like 2^32). Remember that you don't draw the numbers in the diagram. – Calvin's Hobbies – 2014-07-23T07:34:27.867
Should the very first tube on the very first line of tubes be \ or can it be /? – jaybz – 2014-07-23T10:42:16.597
@jaybz It should always be a . – Calvin's Hobbies – 2014-07-23T14:04:10.903
@Calvin'sHobbies: This is a great question, but I passed it by a couple times 'cause it's title seemed too technical/scary-sounding. Maybe you'd get more views if it were simpler/funnier. – Robbie Wxyz – 2014-07-27T01:16:36.653
@SuperScript Thanks :) Can you suggest a more approachable title? – Calvin's Hobbies – 2014-07-27T02:23:34.300