Write a program (or function) that takes in a non-empty string of any printable ASCII characters.
Print (or return) a zigzagging chain of the characters in the string with every neighboring pair of characters linked by:
/
if the first character occurs before the second character in normal ASCII order. e.g.B / A
\
if the first character occurs after the second character in normal ASCII order. e.g.B \ A
-
if the first and second characters are the same. e.g.A-A
So the output for Programming Puzzles & Code Golf
would be
o
/ \
r z-z o e G l
/ \ / \ / \ / \ / \
P o r m-m n u l s & C d f
\ / \ / \ / \ / \ / \ / \ /
g a i g P e
\ /
If there is only one character in the input string the output would just be that character.
Your program should treat ,
/
, \
, and -
just the same as all other characters.
e.g. -\//-- \ //-
should produce:
\
/ \
- /-/
/ \
- --- \ /-/
\ / \ / \
-
\
There should be no extraneous newlines in the output except for a single optional trailing newline. (Note that the empty line in the example just above holds the last space in the the string and is therefore not extraneous.) There may be trailing spaces on any lines in any arrangement.
The shortest code in bytes wins.
One more example - Input:
3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679
Output:
9 9 8 6 6
/ \ / \ / \ / \ / \
9 6 8 7 3 3 4 2 4 8 9 8-8
/ \ / \ / \ / \ / \ / \ / \
4 5 2 5 5 2 3-3 3 7 5 2 4 9 9 9-9 7
/ \ / \ / \ / \ / \ / \ / \ / \ / \
3 1 1 3 2 0 1 7 6 3 3 5 8 8 6
\ / \ / \ / \ / \ / \
. 1 1 5 2 9 9 3 7 1 4 6 8 9
\ / \ / \ / \ / \ / \ / \ / \ /
0 0 7 9 5 2 0 0 2 6 9-9 8 5 4 7
\ / \ / \ / \ / \ / \ / \ /
4 4-4 2 8 8 4 2 3 2 7 6
\ / \ / \ / \ /
0 6 8 3 1-1 0
\ / \ /
2 0