Skip to main content
edited body
Source Link
Jonathan Allan
  • 110.1k
  • 7
  • 65
  • 282

Husk, 8 bytes

ṁ%2Ẋ*∫mL

Try it online!

Approach based on Jonathan Allen'sAllan's Jelly answer. Outputs zero (falsy) for valid paths, non-zero (truthy) for non-valid paths.

      mL  # get the lengths of the input strings
     ∫    # and calculate the cumulative sum
          # (so odd numbers indicate we're in a square)
   Ẋ*     # product of all adjacent pairs
          # (so odd numbers indicate a 2-character move
          # attempted from within a square)
ṁ%2       # map 'modulo 2' to all elements (gets odd numbers)
          # and output sum (non-zero if any elements were odd)

Husk, 8 bytes

ṁ%2Ẋ*∫mL

Try it online!

Approach based on Jonathan Allen's Jelly answer. Outputs zero (falsy) for valid paths, non-zero (truthy) for non-valid paths.

      mL  # get the lengths of the input strings
     ∫    # and calculate the cumulative sum
          # (so odd numbers indicate we're in a square)
   Ẋ*     # product of all adjacent pairs
          # (so odd numbers indicate a 2-character move
          # attempted from within a square)
ṁ%2       # map 'modulo 2' to all elements (gets odd numbers)
          # and output sum (non-zero if any elements were odd)

Husk, 8 bytes

ṁ%2Ẋ*∫mL

Try it online!

Approach based on Jonathan Allan's Jelly answer. Outputs zero (falsy) for valid paths, non-zero (truthy) for non-valid paths.

      mL  # get the lengths of the input strings
     ∫    # and calculate the cumulative sum
          # (so odd numbers indicate we're in a square)
   Ẋ*     # product of all adjacent pairs
          # (so odd numbers indicate a 2-character move
          # attempted from within a square)
ṁ%2       # map 'modulo 2' to all elements (gets odd numbers)
          # and output sum (non-zero if any elements were odd)
Source Link
Dominic van Essen
  • 36.4k
  • 2
  • 22
  • 60

Husk, 8 bytes

ṁ%2Ẋ*∫mL

Try it online!

Approach based on Jonathan Allen's Jelly answer. Outputs zero (falsy) for valid paths, non-zero (truthy) for non-valid paths.

      mL  # get the lengths of the input strings
     ∫    # and calculate the cumulative sum
          # (so odd numbers indicate we're in a square)
   Ẋ*     # product of all adjacent pairs
          # (so odd numbers indicate a 2-character move
          # attempted from within a square)
ṁ%2       # map 'modulo 2' to all elements (gets odd numbers)
          # and output sum (non-zero if any elements were odd)