Submit an Entry

To enter the challenge, you need to signup or login.

This Challenge's Best Entries [View All]

(View the Overall | Perl | PHP | Python | Ruby leaderboard.)

Rank User Size Language Score [?]
1st tybalt89 56 Perl 10,000 (v2)
2nd robin 56 Perl 10,000 (v5)
3rd kinaba 58 Perl 9,655 (v15)
4th shinh 59 Perl 9,491 (v19)
5th ersagun 61 Perl 9,180 (v113)
6th ySas 65 Perl 8,615 (v7)
7th Jasper 65 Perl 8,615 (v6)
8th kounoike 66 Perl 8,484 (v20)
9th ott 67 Perl 8,358 (v15)
10th 0xF 67 Perl 8,358 (v6)

See who is active in this challenge →

Switchboard

(Challenge added 1414 days ago.)

Can you sort out the mess?

Discuss This Challenge →

The Problem

In this challenge, you will receive a diagram of some wiring. The wires start at the top of the diagram, and end at the bottom. The wires may cross over each other. Your task is to follow the paths of the wires to deduce the order of the wires at the bottom.

The first line of the input will be the labels. This is a row of letters, each separated by a single space. On the following lines, wires represented by the pipe character (|) will lead downwards. There are two types of crossover which change the order of the wires.

The first type involves two wires and is shown using an X :

A B
| |
 X
| |

The order of these wires at the bottom of the above diagram is "B A".

The second type of crossover involves three wires. In this case the center wire does not change, but the two outside wires swap places. Here is an example of a three wire crossover :

A B C
| | |
 \|/
  X
 /|\
| | |

The order of the wires at the bottom of this diagram is "C B A".

More Information

  • The diagram will be given to your program on stdin. The first line will contain the labels for the wires separated by spaces. There will be at least 4 wires, and a maximum of 20. The labels will always be in ascending alphabetical order beginning with "A".
  • The remainder of the diagram will follow the labels. The first and last lines will always contain just pipe characters (|) separated by spaces. There will be at most 50 lines in the diagram.
  • There are no limits to the number of times a wire can be involved in a crossover.
  • Your program should print the order of the wires at the bottom of the diagram on stdout. You should print the labels for the wires on one line and separate them by spaces.
  • Your code will be run 6 times for each submission. Your program will need to pass all 6 runs for it to be deemed successful.

Examples

As mentioned above, your program will be run six times. The same diagrams will be given for the first three runs. You can view the input and the expected output by clicking the links below.

For the 4th, 5th and 6th run, your program will receive a different diagram for each run. Click here to see an example, random diagram. Reload the page to get a new diagram.

Thanks

Thanks again to Mark Byers for suggesting and submitting this challenge!