Python Forum
"100 prisoner problem" (attempts)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
"100 prisoner problem" (attempts)
#11
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.
Reply
#12
I am glad you got it working, and thanks for posting the solution.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Failed attempts to load Microsoft Appstore Python DLLs piyushd 0 394 Oct-31-2023, 10:43 AM
Last Post: piyushd
  Shutil attempts to copy directories that don't exist ConsoleGeek 5 4,450 Oct-29-2019, 09:26 PM
Last Post: Gribouillis
  All pip install attempts are met with SSL error flycast 5 76,410 Apr-26-2019, 10:27 PM
Last Post: sathiq

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020