Skip to main content
added 35 characters in body
Source Link
Neil
  • 184.4k
  • 12
  • 76
  • 290

Charcoal, 3232 18 bytes

⊞υ²FS⊞⊞Oυ№_/ι№⌊⭆θ∨¬κ⁼№_/‾ι⊞υ²⌊⭆⪪υ²›⌈ι⌊ιι№\_§θ⊖κ 

Try it online!Try it online! Link is to verbose version of code. Would be 30 bytes if I used ~ but looks nicer. Explanation:

⊞υ² θ Input string 

Push 2 to the predefined list.

FS ⭆ Map over characters and convert to string 

Loop over the input string.

⊞⊞Oυ№_ κ Current index ¬ Logical Not (i.e. is zero) ∨ Logical Or ι Current character № Count (i.e. contained in) _/ι№ Literal _/‾ι (i.e. begins at bottom) 

For each character, push two bits to the list, one for if the character begins at the bottom and one for if it ends at the top.

⊞υ² ⁼ Equals 

Push another 2 to the list.

⌊⭆⪪υ²›⌈ι⌊ι θ Input string § Indexed by κ Current index ⊖ Decremented (i.e. previous character) № Count (i.e. contained in)  \_ Literal \_ (i.e. ended at bottom) ⌊ Minimum (i.e. if all true) Implicitly print 

Compare pairs of bits for inequality. Because of the extra two 2s, this now matches pairs of bits from adjacent characters. The results are then cast to string and the minimum taken, which means that the output is 0 if any of the pairs are the same (meaning that the string is disconnected) and 1 if they are all different (meaning that the string is connected).

Charcoal, 32 bytes

⊞υ²FS⊞⊞Oυ№_/ι№/‾ι⊞υ²⌊⭆⪪υ²›⌈ι⌊ι 

Try it online! Link is to verbose version of code. Would be 30 bytes if I used ~ but looks nicer. Explanation:

⊞υ² 

Push 2 to the predefined list.

FS 

Loop over the input string.

⊞⊞Oυ№_/ι№/‾ι 

For each character, push two bits to the list, one for if the character begins at the bottom and one for if it ends at the top.

⊞υ² 

Push another 2 to the list.

⌊⭆⪪υ²›⌈ι⌊ι 

Compare pairs of bits for inequality. Because of the extra two 2s, this now matches pairs of bits from adjacent characters. The results are then cast to string and the minimum taken, which means that the output is 0 if any of the pairs are the same (meaning that the string is disconnected) and 1 if they are all different (meaning that the string is connected).

Charcoal, 32 18 bytes

⌊⭆θ∨¬κ⁼№_/ι№\_§θ⊖κ 

Try it online! Link is to verbose version of code. Explanation:

 θ Input string  ⭆ Map over characters and convert to string  κ Current index ¬ Logical Not (i.e. is zero) ∨ Logical Or ι Current character № Count (i.e. contained in) _/ Literal _/ (i.e. begins at bottom)  ⁼ Equals  θ Input string § Indexed by κ Current index ⊖ Decremented (i.e. previous character) № Count (i.e. contained in)  \_ Literal \_ (i.e. ended at bottom) ⌊ Minimum (i.e. if all true) Implicitly print 
Source Link
Neil
  • 184.4k
  • 12
  • 76
  • 290

Charcoal, 32 bytes

⊞υ²FS⊞⊞Oυ№_/ι№/‾ι⊞υ²⌊⭆⪪υ²›⌈ι⌊ι 

Try it online! Link is to verbose version of code. Would be 30 bytes if I used ~ but looks nicer. Explanation:

⊞υ² 

Push 2 to the predefined list.

FS 

Loop over the input string.

⊞⊞Oυ№_/ι№/‾ι 

For each character, push two bits to the list, one for if the character begins at the bottom and one for if it ends at the top.

⊞υ² 

Push another 2 to the list.

⌊⭆⪪υ²›⌈ι⌊ι 

Compare pairs of bits for inequality. Because of the extra two 2s, this now matches pairs of bits from adjacent characters. The results are then cast to string and the minimum taken, which means that the output is 0 if any of the pairs are the same (meaning that the string is disconnected) and 1 if they are all different (meaning that the string is connected).