Advertisement
Guest User

Untitled

a guest
Oct 27th, 2016
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. trial = 0;
  2. total_days = 0;
  3. n_trials = 100;
  4. while (trial<n_trials)
  5. {
  6. trial++;
  7. random_set_seed(current_time);
  8.  
  9. for (i=0;i<100;i++) prisoner[i] = false;
  10. lightOn = false;
  11.  
  12. counter = 0;
  13. days = 0;
  14.  
  15. // First prisoner to enter is the light master
  16. counter++;
  17. prisoner[0] = true;
  18. lightOn = true;
  19. while(counter<100)
  20. {
  21. days++;
  22. i = irandom(99);
  23. if (!prisoner[i] and lightOn)
  24. {
  25. prisoner[i] = true;
  26. lightOn = false;
  27. }
  28.  
  29. if (i==0 and !lightOn)
  30. {
  31. lightOn = true;
  32. counter++;
  33. }
  34. }
  35.  
  36. total_days += days;
  37. }
  38.  
  39. show_message("Average assertion time: "
  40. +string(total_days/n_trials/365)
  41. +" years after "+string(n_trials)+" trials.");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement