23
2
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
Details
- Input will be a string containing spaces, newlines and exactly one of each of the first
N
lowercase letters.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.
Examples
Input:
b d
h gi
e f
c a
Output:
b d
|\ /|
| \ / |
| X h+--gi
| / \ | |
|/ \e--f
c a
Input:
dk j
b l
c fg
a m
i h
e
Output:
dk----j
/|| /
b / |l /
|X | \/
c \ fg/\
\|/\ \
a \ m
/| \
i-+----h
e
Input:
eti sqjh k p u cfm vb owgzyx rnd la
Output:
eti--sqjh-k--p--u--cfm-vb-owgzyx-rnd-la
Input:
a
Output:
a
really nice ascii art – Optimizer – 2015-04-13T16:22:33.033
2What if both a X and + overlap should be in the same spot? Or is that not a case we should account for? – theonlygusti – 2015-04-13T17:18:52.037
@theonlygusti "If more than two lines overlap any pair of them will be one of the valid overlaps" As e.g.
/
and-
are invalid overlapsX
and+
(/ \ - and |
) can't occur at the same position. – randomra – 2015-04-13T17:46:16.060Still confused; why not give us some examples? – theonlygusti – 2015-04-13T18:02:18.703
@theonlygusti: Basically, it's not a case you should account for – Claudiu – 2015-04-13T18:41:42.470