Given an ASCII art with |
, _
, and
, check if you can draw the art in one stroke.
Description
Your task is, if the ASCII art is representing lines, then check if you can draw the whole art in one stroke, which means:
- without drawing an already drawn line again
- without lifting and continuing the stroke with skipping blocks
Connection Rules
- A pipe is connected to the left end of the underscore when:
- the pipe is left to the underscore
|_
- the pipe is bottom-left to the underscore, but only when it's below a space
- the pipe is left to the underscore
_
|
- A pipe is connected to the right end of the underscore when:
- the pipe is right to the underscore
_|
- the pipe is bottom-right to the underscore, but only when it's below a space
- the pipe is right to the underscore
_
|
- An underscore is connected to another underscore if it is left/right to it
___
- A pipe is connected to another pipe if it is above/under it
|
|
|
A space should not be viewed as a line but as a gap. It can't connect to a pipe or an underscore.
So this art can be drawn in one stroke:
(Start at the red cross and end at the blue cross)
Rules
- Standard Loopholes apply
- The program must take the ASCII art as input
- Input will not be empty
- Input can be padded with spaces, so it's rectangular
- Standard decision problem output
- This is code-golf, so the shortest answer wins
Examples
[In]:
__
|__|
[Out]: True
[In]:
|__|
|__|
[Out]: False
[In]:
___
|___|_ |
[Out]: False (because of the space)
[In]:
_
|_|_
__|
|__|
[Out]: True
[In]:
_
|_|_
|_|
[Out]: True
[In]:
_ _
|_| |_|
[Out]: False
[In]:
_
|_||_|
[Out]: False (the middle pipes are not connected)
[In]:
__
|_|
[Out]: True (begin top-left)
[In]:
___
|_
[Out]: False (the pipe can't connect to the above underscore)
[In]:
___
|
|
|
[Out]: True
[In] (example by DLosc):
_
|_|_
|_
[Out]: False (the two pipes are connected to each other, and so is each underscore it the upper pipe, but the central underscores are not (because there's a pipe between them) and neither underscore to the lower pipe (because the pipe is not below a space)
Good luck!