Python Forum
"100 prisoner problem" (attempts)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
"100 prisoner problem" (attempts)
#1
Hello guys, i have found a code in the internet that i changed a bit. I tested it for a small group of prisoners , but the problem is, that my result shows always "True".

def my_prisoners(p):
    for i in range(6):
        attempt=0
        idx=i
        found= False
        while attempt<3:
            if p[idx]==i:
                found=True
                break
            else:
                idx=p[idx]
                attempt += 1
        if not found:
            return False
    return True

my_prisoners([5,4,3,2,1,0])

True
Here for example the cycle of the permutation has the longest range 5->4->3->2->1->0->5. However, it still shows "True" and should actually show "False". Only if i change "while attempt<3" to "while attempt<1" it shows False and "True" only for [0,1,2,3,4,5], as its supposed to be. I would be really grateful for some helpful advice.
Reply


Messages In This Thread
"100 prisoner problem" (attempts) - by boris602 - Jan-28-2018, 11:59 AM
RE: "100 prisoner problem" (attempts) - by j.crater - Jan-28-2018, 12:07 PM
RE: "100 prisoner problem" (attempts) - by boris602 - Jan-28-2018, 12:26 PM
RE: "100 prisoner problem" (attempts) - by j.crater - Jan-28-2018, 12:45 PM
RE: "100 prisoner problem" (attempts) - by boris602 - Jan-28-2018, 01:09 PM
RE: "100 prisoner problem" (attempts) - by boris602 - Jan-28-2018, 03:08 PM
RE: "100 prisoner problem" (attempts) - by j.crater - Jan-28-2018, 03:42 PM
RE: "100 prisoner problem" (attempts) - by boris602 - Jan-28-2018, 07:16 PM
RE: "100 prisoner problem" (attempts) - by j.crater - Jan-28-2018, 08:50 PM
RE: "100 prisoner problem" (attempts) - by boris602 - Jan-28-2018, 08:57 PM
RE: "100 prisoner problem" (attempts) - by boris602 - Jan-28-2018, 11:04 PM
RE: "100 prisoner problem" (attempts) - by j.crater - Jan-28-2018, 11:13 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Failed attempts to load Microsoft Appstore Python DLLs piyushd 0 513 Oct-31-2023, 10:43 AM
Last Post: piyushd
  Shutil attempts to copy directories that don't exist ConsoleGeek 5 4,678 Oct-29-2019, 09:26 PM
Last Post: Gribouillis
  All pip install attempts are met with SSL error flycast 5 76,815 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