3 edited body

# Pyth, 43

Km-R2sMdcM%R4-VJjQTtJ0|Fm!s-VKdCm_B^_1dlK


Test Suite

This is probably very golfable, and also not the optimal algorithm for golfing (I expect enumerating all paths will be shorter?)... Anyway, if you find any error with the algorithm please let me know, I think it should work but I've been wrong before!

I'll explain my algorithm using the example input of 1221. This program first maps the digits against their successors, like so: [[1,2],[2,2],[2,1]]. Then it gets their differences mod 4 (Pyth gets the result that matches the sign of the right argument of %, so this is always positive) : [3,0,1]. Then the results are split on 0 and have 2 subtracted from each of them: [[1],[-[1]]1]].

Now that the setup is done, we create a list of [-1,1,-1...] and its negation [1,-1,...], both the same length as the resulting array from before. Then, for each of these lists, perform setwise subtraction between the elements of the list and the list generated in the earlier step. Then, if either of the results contains only empty lists, we output true.

# Pyth, 43

Km-R2sMdcM%R4-VJjQTtJ0|Fm!s-VKdCm_B^_1dlK


Test Suite

This is probably very golfable, and also not the optimal algorithm for golfing (I expect enumerating all paths will be shorter?)... Anyway, if you find any error with the algorithm please let me know, I think it should work but I've been wrong before!

I'll explain my algorithm using the example input of 1221. This program first maps the digits against their successors, like so: [[1,2],[2,2],[2,1]]. Then it gets their differences mod 4 (Pyth gets the result that matches the sign of the right argument of %, so this is always positive) : [3,0,1]. Then the results are split on 0 and have 2 subtracted from each of them: [[1],-[1]].

Now that the setup is done, we create a list of [-1,1,-1...] and its negation [1,-1,...], both the same length as the resulting array from before. Then, for each of these lists, perform setwise subtraction between the elements of the list and the list generated in the earlier step. Then, if either of the results contains only empty lists, we output true.

# Pyth, 43

Km-R2sMdcM%R4-VJjQTtJ0|Fm!s-VKdCm_B^_1dlK


Test Suite

This is probably very golfable, and also not the optimal algorithm for golfing (I expect enumerating all paths will be shorter?)... Anyway, if you find any error with the algorithm please let me know, I think it should work but I've been wrong before!

I'll explain my algorithm using the example input of 1221. This program first maps the digits against their successors, like so: [[1,2],[2,2],[2,1]]. Then it gets their differences mod 4 (Pyth gets the result that matches the sign of the right argument of %, so this is always positive) : [3,0,1]. Then the results are split on 0 and have 2 subtracted from each of them: [[1],[-1]].

Now that the setup is done, we create a list of [-1,1,-1...] and its negation [1,-1,...], both the same length as the resulting array from before. Then, for each of these lists, perform setwise subtraction between the elements of the list and the list generated in the earlier step. Then, if either of the results contains only empty lists, we output true.

2 added 42 characters in body

# Pyth, 43

Km-R2sMdcM%R4-VJjQTtJ0|Fm!s-VKdCm_B^_1dlK


Test Suite

This is probably very golfable, and also not the optimal algorithm for golfing (I expect enumerating all paths will be shorter?)... Anyway, if you find any error with the algorithm please let me know, I think it should work but I've been wrong before!

I'll explain my algorithm using the example input of 1221. This program first maps the digits against their successors, like so: [[1,2],[2,2],[2,1]]. Then it gets their differences mod 4 (Pyth gets the result that matches the sign of the right argument of %, so this is always positive) : [3,0,1]. Then the results are split on 0 and have 2 subtracted from each of them: [[1],-[1]].

Now that the setup is done, we create a list of [-1,1,-1...] and its negation [1,-1,...], both the same length as the resulting array from before. Then, for each of these lists, perform setwise subtraction between the elements of eachthe list and the list generated in the earlier step. Then, if either of the results contains only empty lists, we output true.

# Pyth, 43

Km-R2sMdcM%R4-VJjQTtJ0|Fm!s-VKdCm_B^_1dlK


Test Suite

This is probably very golfable, and also not the optimal algorithm for golfing (I expect enumerating all paths will be shorter?)... Anyway, if you find any error with the algorithm please let me know, I think it should work but I've been wrong before!

I'll explain my algorithm using the example input of 1221. This program first maps the digits against their successors, like so: [[1,2],[2,2],[2,1]]. Then it gets their differences mod 4 (Pyth gets the result that matches the sign of the right argument of %, so this is always positive) : [3,0,1]. Then the results are split on 0 and have 2 subtracted from each of them: [[1],-[1]].

Now that the setup is done, we create a list of [-1,1,-1...] and its negation [1,-1,...], both the same length as the resulting array from before. Then, for each of these lists, perform setwise subtraction between the elements of each list. Then, if either of the results contains only empty lists, we output true.

# Pyth, 43

Km-R2sMdcM%R4-VJjQTtJ0|Fm!s-VKdCm_B^_1dlK


Test Suite

This is probably very golfable, and also not the optimal algorithm for golfing (I expect enumerating all paths will be shorter?)... Anyway, if you find any error with the algorithm please let me know, I think it should work but I've been wrong before!

I'll explain my algorithm using the example input of 1221. This program first maps the digits against their successors, like so: [[1,2],[2,2],[2,1]]. Then it gets their differences mod 4 (Pyth gets the result that matches the sign of the right argument of %, so this is always positive) : [3,0,1]. Then the results are split on 0 and have 2 subtracted from each of them: [[1],-[1]].

Now that the setup is done, we create a list of [-1,1,-1...] and its negation [1,-1,...], both the same length as the resulting array from before. Then, for each of these lists, perform setwise subtraction between the elements of the list and the list generated in the earlier step. Then, if either of the results contains only empty lists, we output true.

1

# Pyth, 43

Km-R2sMdcM%R4-VJjQTtJ0|Fm!s-VKdCm_B^_1dlK


Test Suite

This is probably very golfable, and also not the optimal algorithm for golfing (I expect enumerating all paths will be shorter?)... Anyway, if you find any error with the algorithm please let me know, I think it should work but I've been wrong before!

I'll explain my algorithm using the example input of 1221. This program first maps the digits against their successors, like so: [[1,2],[2,2],[2,1]]. Then it gets their differences mod 4 (Pyth gets the result that matches the sign of the right argument of %, so this is always positive) : [3,0,1]. Then the results are split on 0 and have 2 subtracted from each of them: [[1],-[1]].

Now that the setup is done, we create a list of [-1,1,-1...] and its negation [1,-1,...], both the same length as the resulting array from before. Then, for each of these lists, perform setwise subtraction between the elements of each list. Then, if either of the results contains only empty lists, we output true.