Python Forum

Full Version: "100 prisoner problem" (attempts)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
def my_prisoners(p):
    for i in range(6):
        attempt=0
        idx=i
        found= False
        while attempt<3:
            if p[idx]==i+1:
                found=True
                break
            else:
                idx=p[idx]-1
                attempt += 1
        if not found:
            return False
    return True
I dont know why it has not worked before, but now it randomly works. However, iam very grateful for ur help.
I am glad you got it working, and thanks for posting the solution.
Pages: 1 2