18
1
X Marks the spot
Your goal is to add a cross-hair around the capital X:
Example Input / Output
Input:
mdhyyyyyyyhhhddmmm
mdyyssoo oooosyyyhhhdmm
hsso oossoooooyyhhdhhdmmm
yoooooo oo ssysssyhhdyyyhmmmm
myso oso o oyo hhhdhhyhyhhm mm m
mhsyhhys oss yyyhhhsosyhhmmmmdmmm
mhyhhhy y ssyhoho o shhdmmmmdmmmm
hhyyyh s oo syysyyhhdysso oyhdhhhmmmmm
dhysyys sdysoXoyyyyhhso syshm mmm
hhyhyo o osss y shhyyhd mmmmmm
yyhyyyss o oyyyydmmdmmmmmmmmm mm
ysyhyhhho s osy sdm m mddmmddhydmmm
h oshhhyyyddhoo ooyysshdmdohdmmdmddsshmmm
y oyhhhdhhsyhsssshdddsss hdddyyyhddm
dyyshyyhssyyhyyyyddhhmmdmmmdy syssoosyhdm
hsyyhhhhsoo sooyyhhdoohdhhyhyysoo osdm
doyhhhyyyyhhhysyyy oossyyssso osydm
soyhyyhhhhhhyhyyyooos ohdddm
msoyyyyyyyhyyyyo ooo syyd
ho oyyysooo osso osyd
dhyyysssyyyyyysoosdm
mmdddddmmm
Output:
mdhyyyyyyyhhhddmmm
mdyyssoo oooosyyyhhhdmm
hsso oossoooooyyhhdhhdmmm
yoooooo oo ssysssyhhdyyyhmmmm
myso oso o oyo hhhdhhyhyhhm mm m
mhsyhhys oss | yyyhhhsosyhhmmmmdmmm
mhyhhhy y |ssyhoho o shhdmmmmdmmmm
hhyyyh s oo s|ysyyhhdysso oyhdhhhmmmmm
dhysyys -----X-----hhso syshm mmm
hhyhyo o | osss y shhyyhd mmmmmm
yyhyyyss |o oyyyydmmdmmmmmmmmm mm
ysyhyhhho s |sy sdm m mddmmddhydmmm
h oshhhyyyddhoo ooyysshdmdohdmmdmddsshmmm
y oyhhhdhhsyhsssshdddsss hdddyyyhddm
dyyshyyhssyyhyyyyddhhmmdmmmdy syssoosyhdm
hsyyhhhhsoo sooyyhhdoohdhhyhyysoo osdm
doyhhhyyyyhhhysyyy oossyyssso osydm
soyhyyhhhhhhyhyyyooos ohdddm
msoyyyyyyyhyyyyo ooo syyd
ho oyyysooo osso osyd
dhyyysssyyyyyysoosdm
mmdddddmmm
Input:
000000000000
000000000000
0000X0000000
0000000X0000
000000000000
000000000000
000000000000
000000000000
000000000000
000000000000
000000000000
000000000000
Output:
|
0000|00|0000
0000|00|0000
-----X--+--00
00--+--X-----
0000|00|0000
0000|00|0000
0000000|0000
000000000000
000000000000
000000000000
000000000000
000000000000
Input:
00000000000000000
00000000000000000
00000000000000000
00000X000X0000000
00000000000000000
00000000000000000
00000000000000000
00000000000000000
00000000000000000
00000000000000000
00000000000000000
00000000000000000
Output:
00000|000|0000000
00000|000|0000000
00000|000|0000000
----+#+++#+----00
00000|000|0000000
00000|000|0000000
00000|000|0000000
00000000000000000
00000000000000000
00000000000000000
00000000000000000
00000000000000000
Crosshair
Your cross-hair should be a 3-tall and 5-wide:
|
|
|
-----X-----
|
|
|
Input
Input will be at least 12x12 characters in size and will consist of only ASCII characters. It can be taken in through STDIN or function argument. The input will not always contain an X. Input will be in any shape and have an arbitrary amount of whitespace. The input will not contain any of: +
, -
, #
, and |
Output
Output can be through STDOUT or a function's return value. Output should be the input image with the cross-hair drawn. If there is not enough space to draw the crosshair, you must add lines / spaces to draw it. Overlapping spots should be replaced with a +
. If the |
or -
of the crosshairs overlaps an X
, instead of a +
, an #
should appear.
Trailing whitespace is not allowed except for a single newline at the very end.
This is code-golf so shortest code in bytes wins!
1>
@steveverrill 1. It will be a newline separated string, not an array of strings 2. No, that is not allowed. You can use that in your code but it shouldn't appear in the output – Downgoat – 2015-08-04T04:44:29.067
3Does the
+
for overlapping-
and|
apply only when those characters are part of crosshairs, or does it affect literal-
and|
found in the input as well? – DLosc – 2015-08-04T05:47:34.350Can we assume a rectangular input i.e. all lines (including whitespace) will be the same length? – Level River St – 2015-08-04T09:27:00.933
@steveverrill I think not: The input will not always contain an X. Input will be in any shape and have an arbitrary amount of whitespace., but I agree that it would make things a lot easier. – flawr – 2015-08-04T10:20:42.167
1@DLosc those will not be in the input. I've updated the question – Downgoat – 2015-08-04T15:53:36.013
1What if a literal
#
in the input is encountered by a crosshair? Will it be overwritten? – Kodos Johnson – 2015-08-05T23:08:10.423@Andrew no, # won't be in the inout – Downgoat – 2015-08-05T23:12:34.803
Will all lines of the input always be equal length? – George Reith – 2015-08-06T17:14:59.320
@GeorgeReith no the input's lines may be different lengths – Downgoat – 2015-08-06T17:16:24.820
Damn... I'll need to make another change to my answer then! – Dom Hastings – 2015-08-06T18:46:38.697
Are ASCII nonprintable characters (such as '\t' or '\r') allowed in input? – edc65 – 2015-08-07T20:09:29.207
@edc65 nope, they aren't – Downgoat – 2015-08-07T20:10:17.013