4
\$\begingroup\$

I hate hashes because they remind me of hashtags, help me find them in the input

Input

A piece of text

This is an #example text,
#designed for demo #purposes,
#to demonstrate the challenge.#
  • You may add a optional newline character at the end of the input if your program requires this
  • You may assume that there will be no input longer than 100 lines
  • You may freely assume there will be no line longer than 100 characters
  • You should assume the input doesn't contain any trailing spaces
  • You may alternatively take the input as a list of lines

Challenge

Surround every hash symbol with an hit article, to help me find it

  |
--#--
  |
  • If the hash symbol on the first line, you need to add more lines to the top of the grid
  • If the hash symbol is too far to the left, you need to prefix all lines with spaces to make place for the left side of the hitmarker
  • If the hash symbol if too far to the bottom of the text, add more lines
  • If an hitmarker of another hash symbol overwrites the hitmarker of the first hash symbol, it doesn't matter what one wins (see example 5)
  • An hitmarker may not overwrite any other hash symbol, but should overwrite the text

Output

Another piece of text, that has the hit markers on the correct place

             |
  |his is a--#--ample|text,
--#--signed f|r dem--#--rposes, |
--#-- demonstrate the|challeng--#--
  |                             |
  • You should treat the input as a "matrix" of characters, and you should only extend this "matrix" in the directions required if the hitmarker doesn't fit the grid (so a hash symbol in line 0 means extending the grid to line -1, a hash symbol in column 0 means extending it to columns -2, etc...)
  • When you output the matrix, you should strip any trailing spaces
  • The output may contain a trailing newline, as long as that line is empty (this is to accomplish for launches that only have a print_and_output_newline function)

Test cases

1: In:

a

1: Output:

a

2: In:

#

2: Out:

  |
--#--
  |

3: In:

#a
aa

3: Out:

  |
--#--
  |a

4: In:

aa
a#

4: Out:

 a|
--#--
  |

5: In:

###
#a#

5: Out:

  |||
--###--
--#-#--
  | |

5: Or:

  |||
--###--
--#|#--
  | |

6: In:

a
a
#
a
a

6: Out:

  a
  |
--#--
  |
  a
\$\endgroup\$
0

0

Browse other questions tagged or ask your own question.