manish icon

Untitled

manish | PRO | 01/08/23 11:44:24 AM UTC | 0 ⭐ | 1233 👁️ | Never ⏰ | []
Python |

370 B

|

None

|

0 👍

/

0 👎

queue = [[1, 2, 3, 4, 5]]
 
path = {str(queue[0]): []}
 
while queue:
    x = queue.pop(0)
    for i in range(1, 6):
        y = x[:i][::-1] + x[i:]
        for j in range(i):
            y[j] = y[j] - 5 if y[j] > 5 else y[j] + 5
        if str(y) not in path:
            path[str(y)] = path[str(x)] + [i]
            queue += [y]
print(path[str([5, 4, 3, 2, 1])])

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎