23
Write a program that takes in a rectangular block of text made up of X
's and .
's, such as this rough A
:
......
..XX..
.X..X.
.XXXX.
.X..X.
.X..X.
Output a representation of this grid rotated 45 degrees counterclockwise by drawing a slash — forward or backward depending on context — everywhere an X
borders a .
or the side of the grid (with spaces filling in the rest):
/\/\
/ /\ \
\/ / \
/\/ /\ \
\ / \/
\ \
\ \
\/
The number of trailing and leading spaces (and newlines) doesn't matter as long as the shape of the X
's in the input is maintained by the slashes. It's ok to trim extra rows or columns of .
's.
For I/O you may use any combination of stdin/stdout/files/command line parameters. For example your script might take in a file name of the X.
pattern and rewrite the file with the slash pattern. Or your script might take in the X.
pattern from stdin line by line (pressing d
when done) and output the result to stdout.
The input may be arbitrarily large, but you may assume it is always well formatted.
No characters besides / \
and newlines should be in any output.
Scoring
The shortest code in bytes wins. Use https://mothereff.in/byte-counter as a byte counter if you use non-ASCII characters.
Bonus: Minus 50 bytes if you can change (replace, not remove) one character in your program so it outputs the slash grid rotated 45 degrees clockwise, e.g.:
/\/\
/ /\ \
/ \ \/
/ /\ \/\
\/ \ /
/ /
/ /
\/
Input Samples
XXXXXXXXX
X.......X
X.XXXXX.X
X.X...X.X
X.X.X.X.X
X.X...X.X
X.XXXXX.X
X.......X
XXXXXXXXX
XXX...XXX....XXX...XXX
X..X..X..X..X.....X...
XXX...XXX...X.....X.XX
X.....X.....X.....X..X
X.....X......XXX...XXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX...X
X...X...............X...............X...........X...................X...X
X...X...XXXXXXXXX...X...XXXXX...XXXXXXXXX...XXXXX...XXXXX...XXXXX...X...X
X...............X.......X...X...........X...........X...X...X.......X...X
XXXXXXXXX...X...XXXXXXXXX...XXXXXXXXX...XXXXX...X...X...X...XXXXXXXXX...X
X.......X...X...............X...........X...X...X...X...X...........X...X
X...X...XXXXXXXXXXXXX...X...X...XXXXXXXXX...XXXXX...X...XXXXXXXXX...X...X
X...X...............X...X...X.......X...........X...........X.......X...X
X...XXXXXXXXXXXXX...XXXXX...XXXXX...X...XXXXX...XXXXXXXXX...X...XXXXX...X
X...........X.......X...X.......X...X.......X...........X...X...........X
X...XXXXX...XXXXX...X...XXXXX...X...XXXXXXXXX...X...X...X...XXXXXXXXXXXXX
X.......X.......X...X...X.......X.......X.......X...X...X.......X.......X
XXXXXXXXXXXXX...X...X...X...XXXXXXXXX...X...XXXXX...X...XXXXX...XXXXX...X
X...........X...X...........X.......X...X.......X...X.......X...........X
X...XXXXX...X...XXXXXXXXX...XXXXX...X...XXXXX...XXXXX...XXXXXXXXXXXXX...X
X...X.......X...........X...........X.......X...X...X...............X...X
X...X...XXXXXXXXX...X...XXXXX...XXXXXXXXX...X...X...XXXXXXXXXXXXX...X...X
X...X...........X...X...X...X...X...........X...............X...X.......X
X...XXXXXXXXX...X...X...X...XXXXX...XXXXXXXXX...XXXXXXXXX...X...XXXXXXXXX
X...X.......X...X...X...........X...........X...X.......X...............X
X...X...XXXXX...XXXXX...XXXXX...XXXXXXXXX...XXXXX...X...XXXXXXXXX...X...X
X...X...................X...........X...............X...............X...X
X...XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Related Questions:
Draw the Hilbert curve using slashes
Align a horizontally-aligned, right-angled ASCII shape along a diagonal
Is replacing the single character with a whitespace character (or a whitespace to a symbol) acceptable? – Reinstate Monica - ζ-- – 2014-09-06T16:39:19.627
@hexafraction Sure – Calvin's Hobbies – 2014-09-06T16:40:56.443
What we need is someone to answer this in itflabtijtslwi. Then we'd have "Drawing in Slashes in Slashes."
– Justin – 2014-09-06T23:43:04.850