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

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

1 comment thread

General comments (5 comments)
General comments
Razetime‭ wrote about 3 years ago

I think this looks good. Could diagonal lines be a thing?

trichoplax‭ wrote about 3 years ago

Until I read as far as the notes section, I had assumed that each answer would have to deal with any sufficient subset of the possible inputs (rather than being written to handle one specific sufficient subset). That sounded like an interesting challenge but might have made input format tricky. The notes make it perfectly clear this isn't the case, but a change of wording earlier on might make it even clearer.

dzaima‭ wrote about 3 years ago

@Razetime Diagonal lines can't really be overlapped, which is the whole point. Like, there's no character for /+|

user‭ wrote about 3 years ago

@dzaima There is if you're willing to go into Unicode ( and others), but I guess that'd just make it really complicated and would be difficult for languages without Unicode.

dzaima‭ wrote about 3 years ago

Well, you'd also need | + - + / and | + - + \