# Is this continuous terrain? Part II

Caves and Cliffs edition

You're given a piece of ASCII art representing a piece of land, like so:

   /‾\         _ __
__/ _/         \‾
_/  __/‾\     |
/   /     ‾\   |
\_/‾        \_/


But unlike in the previous challenge, the terrain is mountainous, with caves and cliffs, and can turn back on itself. Also, a new character is introduced, |, which can connect to any of its four corners.

Since an overline (‾) is not ASCII, you can use a ~ or - instead.

Your challenge is still to determine if it is connected by the lines of the characters such that a single line connects them all without backtracking or crossing itself. For example, the above can be traced like so:

To clarify the connections:

• _ can only connect on the bottom on either side
• ‾ (or ~ or -) can only connect on the top on either side
• / can only connect on the top right and bottom left
• \ can only connect on the top left and bottom right
• | can connect on all four corners, but not to anything that connects to more than one corner. | must have a single connection above itself and a single connection below.

That one's a bit confusing, so the following are legal:

|
\

|
\

_
|_

‾|
/


And the following aren't:

|
‾
_
|

||


It doesn't matter where the connections start and end as long as they're all connected. Note that one line's bottom is the next line's top, so stuff like this is allowed:

_
‾

\
\

_
/

\
‾


You can assume input will only contain those characters plus spaces and newlines, and will contain at least one non-space character per column.

Input can be taken as ASCII art, an array of rows, a character matrix, etc.

## Testcases

Separated by double newline.

Truthy:

\
\

\_
\ /\/\_
‾     \

/\
\/

\_
‾\

/‾\
__/   ‾\_
\_/‾\
\

/‾\         _ __
__/ _/         \‾
_/  __/‾\     |
/   /     ‾\   |
\_/‾        \_/

/‾\
\ /
/ \

____   _
___| | |
|  ___| |
| |___  |
|___  | |
___| | |
|_____| |

_
/ \  _
| |_|

_
|_\



Falsy:

/
\

//

‾‾
/  \

‾
_

\____/
/‾‾‾\

\_
/

| |
‾‾‾

|_|
| |

• So self-intersections, nested regions, etc, are all allowed? So long as there is a path from each cell to every other cell? For example: Try it online! Jan 22 at 19:12
• Hmm... based on some of the falsy examples that must be falsy. is the rule that your single connected line tracing it is not allowed to backtrack? Jan 22 at 19:14
• @Jonah No self-intersections, yes the line can't backtrack. Jan 22 at 19:18
• What if there is an input that has a continuous line and a disconnected (but continuous) loop? Is it continuous? Jan 23 at 14:08
• @AnttiP Example? Jan 23 at 19:13

# Charcoal, 190 bytes

ＷＳ⊞υιＦυ«⸿Ｆι«Ｍ³→Ｆ№\|/κＰ|@#≡κ_Ｐ^²‾ＰV²/Ｐ/²\Ｐ\²»⸿⸿»Ｊ⁰¦⁰Ｆυ«⸿Ｆι«Ｍ³→≡κ|Ｆ⁸¿‹ ⊟ＫＤ³✳λＰ✳λ²»⸿⸿»ＵＭＫＡ⎇⁼#ιψι≔⟦⟧θＦ×³ＬυＦ×³⊕⌈ＥυＬκ«Ｊκι≔ＬΦＫＭ‹ λη¿∧‹ ＫＫ›²η⊞θ⟦ικη⟧»¿∨⁻²Ｌθ⊙θ⊖⊟ι⎚«≔⊟θηＪ⊟η⊟ηＷ⌕ＡＥＫＭ‹ κ¹✳⁻³⊟ιψ¿⊖ＬＫＡ⎚«⎚¹


Try it online! Link is to verbose version of code. Takes input as a list of newline-terminated strings and outputs a Charcoal boolean, i.e. - for continuous, nothing if not. Explanation:

ＷＳ⊞υι


Input the terrain.

Ｆυ«


Loop over the rows of the terrain.

⸿


Start each row on a new line. This is because we'll be drawing above the current line, so we want the actual drawing to start at row 0.

Ｆι«


Loop over each character of the row.

Ｍ³→


Space the characters 3 apart. (This should be one before and two after, but unfortunately Switch makes doing that less golfy.)

Ｆ№\|/κ


If the current character is a \, | or /, then...

Ｐ|@#


... output a marker in case the character above or below is a |.

≡κ


Switch on the current character.

_Ｐ^²


If it's a _ then write to the centre and the bottom left and bottom right corners of this 3×3 square.

‾ＰV²


If it's a ‾ then write to the centre and the top left and top right corners.

/Ｐ/²


If it's a / then draw from the bottom left to the top right.

\Ｐ\²


If it's a \ then draw from the top left to the bottom right.

»⸿⸿


Add another two rows so that each row is spaced 3 apart vertically as well.

»Ｊ⁰¦⁰


Jump back to the beginning.

Ｆυ«⸿Ｆι«Ｍ³→


Loop through the rows and columns as before.

≡κ|


This time, only process | characters.

Ｆ⁸


Check all 8 directions. (Actually directions 0 and 4 are useless, but it's easier to include them.)

¿‹ ⊟ＫＤ³✳λ


See if there's a \, | or / in that direction.

Ｐ✳λ²


If so then draw a connection to it.

»⸿⸿


Finish processing each row.

»ＵＭＫＡ⎇⁼#ιψι


Remove any unused #s.

≔⟦⟧θ


Start collecting points that do not have two neighbours.

Ｆ×³ＬυＦ×³⊕⌈ＥυＬκ«Ｊκι


Loop over each cell of the canvas, taking into account that it's offset by 2 characters to the right.

≔ＬΦＫＭ‹ λη


Get the number of neighbours of this cell.

¿∧‹ ＫＫ›²η


If this cell is not empty and does not have two neighbours, then...

⊞θ⟦ικη⟧


... add it to the list.

»¿∨⁻²Ｌθ⊙θ⊖⊟ι


If there aren't exactly two points with exactly one neighbour each, then...

⎚«


... simply clear the canvas, otherwise:

≔⊟θηＪ⊟η⊟η


Ｗ⌕ＡＥＫＭ‹ κ¹


While there is an adjacent character...

✳⁻³⊟ιψ


... erase the current character and move in that direction.

¿⊖ＬＫＡ


If there is more than one character left, then...

⎚


... simply clear the canvas, otherwise...

«⎚¹


... clear the canvas and output success.