News for hackers. Stuff that matters.
Re:Puzzle: 100 Prisoners and a Light Bulb by mrtron on Tuesday November 13, 2007 @07:30PM (#79594)
Thanks.

 import random
 def run():
 	prisoners = {}
 	for x in range(100):
 	 prisoners[x]=0
 	days=0; counter=0; bulb=0
 	while counter<100:
 	 prisoner = random.randint(0, 99) 
 	 days += 1
 	 if prisoner == 0:
 	  if bulb == 1:
 	    bulb = 0; counter += 1
 	 else:
 	   if prisoners[prisoner] == 0 and bulb == 0:
 	     bulb=1
 	return days

There are no comments on this comment yet.