You should write a program or function which receives a block of chars represented as a string and outputs or returns a similar string in which the letters adjacent in the alphabet are connected.
A visual example (in the form of
input => output):
b d b d |\ /| | \ / | => | X | | / \ | e |/ \e c a c a
- Input will be a string containing spaces, newlines and exactly one of each of the first
1 <= N <= 26
- The lines of the input will be padded with spaces creating a full rectangular block.
- Every pair of letters adjacent in the alphabet will be on the same row, column or diagonal line and should be connected with a straight ascii line using
\ / | or -. (The line might have a length of 0.)
The following types of two-line overlaps should be handled:
/ and \ become X | and - become + / and / become / \ and \ become \ | and | become | - and - become - [letter] and [anything] become [letter]
No other kind of two-line overlap will occur.
- If more than two lines overlap any pair of them will be guaranteed to be one of the valid overlaps. (e.g.
[letter] / |triplet will never occur)
- Apart from changing spaces into
\ / | - X and +input and output should be identical.
- Trailing newline is optional but have to be the same for input and output.
- This is code-golf so the shortest entry wins.
b d h gi e f c a
b d |\ /| | \ / | | X h+--gi | / \ | | |/ \e--f c a
dk j b l c fg a m i h e
dk----j /|| / b / |l / |X | \/ c \ fg/\ \|/\ \ a \ m /| \ i-+----h e
eti sqjh k p u cfm vb owgzyx rnd la