Caves and Cliffs edition

Part 1, Very related

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:

enter image description here

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.


Separated by double newline.



  \ /\/\_
   ‾     \



__/   ‾\_

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

\ /
/ \

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

/ \  _
| |_|





/  \




| |

| |
  • \$\begingroup\$ 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! \$\endgroup\$
    – Jonah
    Commented Jan 22, 2022 at 19:12
  • \$\begingroup\$ 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? \$\endgroup\$
    – Jonah
    Commented Jan 22, 2022 at 19:14
  • \$\begingroup\$ @Jonah No self-intersections, yes the line can't backtrack. \$\endgroup\$
    – emanresu A
    Commented Jan 22, 2022 at 19:18
  • \$\begingroup\$ What if there is an input that has a continuous line and a disconnected (but continuous) loop? Is it continuous? \$\endgroup\$
    – AnttiP
    Commented Jan 23, 2022 at 14:08
  • \$\begingroup\$ @AnttiP Example? \$\endgroup\$
    – emanresu A
    Commented Jan 23, 2022 at 19:13

1 Answer 1


Charcoal, 190 bytes

WS⊞υιFυ«⸿Fι«M³→F№\|/κP|@#≡κ_P^²‾PV²/P/²\P\²»⸿⸿»J⁰¦⁰Fυ«⸿Fι«M³→≡κ|F⁸¿‹ ⊟KD³✳λP✳λ²»⸿⸿»UMKA⎇⁼#ιψι≔⟦⟧θF׳LυF׳⊕⌈EυLκ«Jκι≔LΦKM‹ λη¿∧‹ KK›²η⊞θ⟦ικη⟧»¿∨⁻²Lθ⊙θ⊖⊟ι⎚«≔⊟θηJ⊟η⊟ηW⌕AEKM‹ κ¹✳⁻³⊟ιψ¿⊖LKA⎚«⎚¹

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.


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.)

¿‹ ⊟KD³✳λ

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.

≔LΦKM‹ λη

Get the number of neighbours of this cell.

¿∧‹ KK›²η

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:


Jump to one of the two ends.

W⌕AEKM‹ κ¹

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.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.