1. Список говнокодов пользователя guest2011

    Всего: 1

  2. Java / Говнокод #6954

    +70

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    import java.util.Random;
    public class A {
    	public static void main(String args[]) {
    		int minimalSuccessTime = Integer.MAX_VALUE;
    		int maximalSuccessTime = Integer.MIN_VALUE;
    		for(int i = 0; i < 10000; i++) {
    			Random rnd = new Random();
    			boolean state = rnd.nextBoolean();
    			final byte prisonersCount = 100;
    			boolean prisoners[] = new boolean[prisonersCount];
    			byte prisonersCounted = 1;
    			int daysPassed = 0;
    			while(true) {
    				daysPassed++;
    				int tmp = rnd.nextInt(prisonersCount);
    				if(tmp == 0) {
    					if(state) {
    						state = false;
    						prisonersCounted++;
    						if(prisonersCounted == prisonersCount) {
    							break;
    						}
    					}
    				} else {
    					if(!state && !prisoners[tmp]) {
    						state = true;
    						prisoners[tmp] = true;
    					}
    				}
    			}
    			if(daysPassed < minimalSuccessTime) {
    				minimalSuccessTime = daysPassed;
    			}
    			if(daysPassed > maximalSuccessTime) {
    				maximalSuccessTime = daysPassed;
    			}
    		}
    		System.out.println("Minimal success time ~= " + minimalSuccessTime/365 + " years!");
    		System.out.println("Maximal success time ~= " + maximalSuccessTime/365 + " years!");
    	}
    }

    One hundred prisoners have been newly ushered into prison. The warden tells
    them that starting tomorrow, each of them will be placed in an isolated cell,
    unable to communicate amongst each other. Each day, the warden will choose
    one of the prisoners uniformly at random with replacement, and place him in
    a central interrogation room containing only a light bulb with a toggle switch.
    The prisoner will be able to observe the current state of the light bulb. If he
    wishes, he can toggle the light bulb. He also has the option of announcing that
    he believes all prisoners have visited the interrogation room at some point in
    time. If this announcement is true, then all prisoners are set free, but if it is
    false, all prisoners are executed.
    The warden leaves, and the prisoners huddle together to discuss their fate.
    Can they agree on a protocol that will guarantee their freedom?

    guest2011, 14 Июня 2011

    Комментарии (13)