Jan-28-2018, 11:59 AM
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]) TrueHere 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.