Comments on Draw a line over ASCII
Post
Draw a line over ASCII
+3
−0
Challenge
Given a multiline string, list of lines, a character matrix or equivalent, and a description of a line, draw a line made out of either '|'
or '-'
over it.
The given text will consist of characters " -|+"
. A '-'
drawn over '|'
or vice versa makes a '+'
, and drawing over a '+'
doesn't change it. All other combinations just override the previous character (that is, space is always overridden and drawing over an equal character doesn't change anything).
You can choose what information about the location of the line you will receive, from these options:
- the starting position (location of the top-left-most character)
- the ending position (location of the bottom-right-most character)
- direction (i.e. horizontal or vertical, given as a boolean or numbers 0/1; which is which doesn't matter)
- length (can have a constant offset of ±1)
Examples
All examples have the input text
" "
"-+--- "
" | --"
1;0 → 4;0 (horizontal, length 4):
" ---- "
"-+--- "
" | --"
4;0 → 4;1 (vertical, length 2):
" | "
"-+--+ "
" | --"
1;0 → 1;2 (vertical, length 3):
" | "
"-+--- "
" | --"
0;2 → 5;2 (horizontal, length 6):
" "
"-+--- "
"-+----"
Notes
- The answer chooses which inputs are expected to be given (including redundant ones), so has to handle only one case.
- The coordinates can be taken as either 0-indexed or 1-indexed.
- The line will have a length of at least 2, ensuring that the start and end coordinates are always a sufficient description.
- The line will always need to be placed in the bounds of the input.
- If applicable, the solution can mutate the input text instead of outputting/returning a modified version.
- Shortest answer per language, scored in bytes, wins!
1 comment thread