92
16
Write a program that takes a single line string that you can assume will only contain the characters /\_‾
. (That's forward and backward slash, underline and overline. You can use ~
in place of overline if you need since overline is not convenient ASCII.)
For example, one possible input is:
__/‾‾\/\_/‾
Your program needs to output a truthy or falsy value depending on whether the left edge of the string is "connected", so to speak, to the right edge of the string via the lines of the characters. So, if the kerning was a bit less, there would be a solid black (albeit kinky) line all the way from the left edge to the right, like an unbroken piece of string or twine.
The output for the above example would be true because the edges are connected:
To be clear on the connections:
/
connects on its bottom left and top right\
connects on its top left and bottom right_
connects on its bottom left and bottom right‾
(or~
) connects on its top left and top right
Also:
It doesn't matter whether the edges of the string started on the top or the bottom, it only matters that they connect horizontally through the whole length of the string.
You can assume the input string is non-empty, and of course just one line.
Here are some more examples followed by 1 (truthy) if they are connected or 0 (falsy) if not:
__/‾‾\/\_/‾
1
_
1
\
1
/
1
‾
1
___
1
\/
1
/\/
1
/\/\
1
‾‾‾
1
\\
0
‾‾
1
_‾
0
‾_
0
\_____/
1
\/\\/\\___
0
\/\__/‾‾\
1
______/\_____
1
‾‾‾‾‾‾\\_____
0
‾‾‾‾‾‾\______
1
_____/‾‾‾‾‾
1
\___/‾‾‾\___/‾‾‾
1
\_/_\_
0
\_/\_
1
/\/\/\/\/\/\/\/\/\/\/\/
1
____________________
1
‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
1
‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾/
0
‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾\
1
/\‾/\‾___/\_\/__\/\‾‾
0
The shortest code is the winner.
37Welcome to PPCG! Nice first challenge. – AdmBorkBork – 2019-03-18T15:30:44.783
1Are the characters specified in your challenge the only ones that will appear in the string? – Embodiment of Ignorance – 2019-03-18T15:31:58.967
@EmbodimentofIgnorance Yes, only the 4. – Discrete Games – 2019-03-18T15:34:11.823
31Wait you could make a language out of this – Delioth – 2019-03-18T18:57:16.427
Vaguely related. – DLosc – 2019-03-18T21:31:45.803
2@Arnauld No, I really think only truthy for connected and falsy for unconnected. (Unless allowing a swap is normal for this kind of question?) – Discrete Games – 2019-03-19T04:35:34.543
@DiscreteGames No, this is not a default rule or practice for this tag. Some challenges allow it, but this is left at the sole discretion of the OP. – Arnauld – 2019-03-19T11:07:45.130
Is there a max length limit? – smci – 2019-03-20T23:48:40.800
@smci No, the input string should be able to be very long, in the thousands of characters (but below string length limits of an average language). – Discrete Games – 2019-03-21T13:41:23.980