Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Sandbox

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!
History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

1 comment thread

General comments (5 comments)