Skip to main content
added 33 characters in body
Source Link
Zgarb
  • 42.8k
  • 4
  • 79
  • 259

Haskell, 93 88 87 bytes

any(all(\(a,b:c)->1>mod(a!!1-b)4).(zip=<<tail)).mapM((\a->[[a,a+1],[a+1,a]]).read.pure)

The last lineThis evaluates to an anonymous function that takes a string and returns a boolean. Test suite here.

Explanation

The idea is that the lambda on the right maps a number a to [[a,a+1],[a+1,a]], the two possible "moves" that take the crank over that number, according to the following diagram:

  1 (2) 2

(1/5)  (3)

  4 (4) 3

In the main anonymous function, we first do mapM((...).read.pure), which converts each character to an integer, applies the above lambda to it, and chooses one of the two moves, returning the list of all resulting move sequences. Then, we check if any of these sequences has the property that the second number of each move equals the first number of the next modulo 4, which means that it's a physically possible sequence. To do this, we zip each move sequence with its tail, check the condition for all the pairs, and see if any sequence evaluates to True.

Haskell, 93 88 87 bytes

any(all(\(a,b:c)->1>mod(a!!1-b)4).(zip=<<tail)).mapM((\a->[[a,a+1],[a+1,a]]).read.pure)

The last line evaluates to an anonymous function. Test suite here.

Explanation

The idea is that the lambda on the right maps a number a to [[a,a+1],[a+1,a]], the two possible "moves" that take the crank over that number, according to the following diagram:

  1 (2) 2

(1/5)  (3)

  4 (4) 3

In the main anonymous function, we first do mapM((...).read.pure), which converts each character to an integer, applies the above lambda to it, and chooses one of the two moves, returning the list of all resulting move sequences. Then, we check if any of these sequences has the property that the second number of each move equals the first number of the next modulo 4, which means that it's a physically possible sequence. To do this, we zip each move sequence with its tail, check the condition for all the pairs, and see if any sequence evaluates to True.

Haskell, 93 88 87 bytes

any(all(\(a,b:c)->1>mod(a!!1-b)4).(zip=<<tail)).mapM((\a->[[a,a+1],[a+1,a]]).read.pure)

This evaluates to an anonymous function that takes a string and returns a boolean. Test suite here.

Explanation

The idea is that the lambda on the right maps a number a to [[a,a+1],[a+1,a]], the two possible "moves" that take the crank over that number, according to the following diagram:

  1 (2) 2

(1/5)  (3)

  4 (4) 3

In the main anonymous function, we first do mapM((...).read.pure), which converts each character to an integer, applies the above lambda to it, and chooses one of the two moves, returning the list of all resulting move sequences. Then, we check if any of these sequences has the property that the second number of each move equals the first number of the next modulo 4, which means that it's a physically possible sequence. To do this, we zip each move sequence with its tail, check the condition for all the pairs, and see if any sequence evaluates to True.

Fixed copy-paste error.
Source Link
Zgarb
  • 42.8k
  • 4
  • 79
  • 259

Haskell, 93 88 8687 bytes

any(all(\(a,b:c)->1>mod(a!!1-b)4).(zip=<<tail)).mapM((\a->[a>[[a,a+1],[a+1,a]]).read.pure)

The last line evaluates to an anonymous function. Test suite here.

Explanation

The idea is that the lambda on the right maps a number a to [[a,a+1],[a+1,a]], the two possible "moves" that take the crank over that number, according to the following diagram:

  1 (2) 2

(1/5)  (3)

  4 (4) 3

In the main anonymous function, we first do mapM((...).read.pure), which converts each character to an integer, applies the above lambda to it, and chooses one of the two moves, returning the list of all resulting move sequences. Then, we check if any of these sequences has the property that the second number of each move equals the first number of the next modulo 4, which means that it's a physically possible sequence. To do this, we zip each move sequence with its tail, check the condition for all the pairs, and see if any sequence evaluates to True.

Haskell, 93 88 86 bytes

any(all(\(a,b:c)->1>mod(a!!1-b)4).(zip=<<tail)).mapM((\a->[a,a+1],[a+1,a]]).read.pure)

The last line evaluates to an anonymous function. Test suite here.

Explanation

The idea is that the lambda on the right maps a number a to [[a,a+1],[a+1,a]], the two possible "moves" that take the crank over that number, according to the following diagram:

  1 (2) 2

(1/5)  (3)

  4 (4) 3

In the main anonymous function, we first do mapM((...).read.pure), which converts each character to an integer, applies the above lambda to it, and chooses one of the two moves, returning the list of all resulting move sequences. Then, we check if any of these sequences has the property that the second number of each move equals the first number of the next modulo 4, which means that it's a physically possible sequence. To do this, we zip each move sequence with its tail, check the condition for all the pairs, and see if any sequence evaluates to True.

Haskell, 93 88 87 bytes

any(all(\(a,b:c)->1>mod(a!!1-b)4).(zip=<<tail)).mapM((\a->[[a,a+1],[a+1,a]]).read.pure)

The last line evaluates to an anonymous function. Test suite here.

Explanation

The idea is that the lambda on the right maps a number a to [[a,a+1],[a+1,a]], the two possible "moves" that take the crank over that number, according to the following diagram:

  1 (2) 2

(1/5)  (3)

  4 (4) 3

In the main anonymous function, we first do mapM((...).read.pure), which converts each character to an integer, applies the above lambda to it, and chooses one of the two moves, returning the list of all resulting move sequences. Then, we check if any of these sequences has the property that the second number of each move equals the first number of the next modulo 4, which means that it's a physically possible sequence. To do this, we zip each move sequence with its tail, check the condition for all the pairs, and see if any sequence evaluates to True.

Golfed g away
Source Link
Zgarb
  • 42.8k
  • 4
  • 79
  • 259

Haskell, 93 88 8886 bytes

g a=[[a,a+1],[a+1,a]]
any(all(\(a,b:c)->1>mod(a!!1-b!!0)4).(zip=<<tail)).mapM(g(\a->[a,a+1],[a+1,a]]).read.pure)

The last line evaluates to an anonymous function. Test suite here.Test suite here.

Explanation

The idea is that gthe lambda on the right maps a number a to [[a,a+1],[a+1,a]], the two possible "moves" that take the crank over that number, according to the following diagram:

  1 (2) 2

(1/5)  (3)

  4 (4) 3

In the main anonymous function, we first do mapM(g(...).read.pure), which converts each character to an integer and, applies gthe above lambda to it, and returnschooses one of the two moves, returning the list of all possibleresulting move sequences. Then, we check if any of these sequences has the property that the second number of each move equals the first number of the next modulo 4, which means that it's a physically possible sequence. To do this, we zip each move sequence with its tail, check the condition for all the pairs, and see if any sequence evaluates to True.

Haskell, 93 88 bytes

g a=[[a,a+1],[a+1,a]]
any(all(\(a,b)->1>mod(a!!1-b!!0)4).(zip=<<tail)).mapM(g.read.pure)

The last line evaluates to an anonymous function. Test suite here.

Explanation

The idea is that g maps a number a to [[a,a+1],[a+1,a]], the possible "moves" that take the crank over that number, according to the following diagram:

  1 (2) 2

(1/5)  (3)

  4 (4) 3

In the main anonymous function, we first do mapM(g.read.pure), which converts each character to an integer and applies g to it, and returns the list of all possible move sequences. Then, we check if any of these sequences has the property that the second number of each move equals the first number of the next modulo 4, which means that it's a physically possible sequence. To do this, we zip each move sequence with its tail, check the condition for all the pairs, and see if any sequence evaluates to True.

Haskell, 93 88 86 bytes

any(all(\(a,b:c)->1>mod(a!!1-b)4).(zip=<<tail)).mapM((\a->[a,a+1],[a+1,a]]).read.pure)

The last line evaluates to an anonymous function. Test suite here.

Explanation

The idea is that the lambda on the right maps a number a to [[a,a+1],[a+1,a]], the two possible "moves" that take the crank over that number, according to the following diagram:

  1 (2) 2

(1/5)  (3)

  4 (4) 3

In the main anonymous function, we first do mapM((...).read.pure), which converts each character to an integer, applies the above lambda to it, and chooses one of the two moves, returning the list of all resulting move sequences. Then, we check if any of these sequences has the property that the second number of each move equals the first number of the next modulo 4, which means that it's a physically possible sequence. To do this, we zip each move sequence with its tail, check the condition for all the pairs, and see if any sequence evaluates to True.

deleted 144 characters in body
Source Link
Zgarb
  • 42.8k
  • 4
  • 79
  • 259
Loading
added 125 characters in body
Source Link
Zgarb
  • 42.8k
  • 4
  • 79
  • 259
Loading
added 746 characters in body
Source Link
Zgarb
  • 42.8k
  • 4
  • 79
  • 259
Loading
Source Link
Zgarb
  • 42.8k
  • 4
  • 79
  • 259
Loading