fork(1) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. static Random rand = new Random(123456L);
  11.  
  12. static void shuffle(int[] list)
  13. {
  14. for (int i = 0; i < list.length; ++i)
  15. {
  16. int a = rand.nextInt(list.length);
  17. int b = rand.nextInt(list.length);
  18.  
  19. // Swap
  20. int t = list[a];
  21. list[a] = list[b];
  22. list[b] = t;
  23. }
  24. }
  25.  
  26.  
  27. public static void main (String[] args) throws java.lang.Exception
  28. {
  29. // your code goes here
  30.  
  31. // Init
  32. int[] list = new int[1000];
  33.  
  34. init(list);
  35. shuffle(list);
  36. show(list);
  37. System.out.println("[new 1000]shuffle");
  38. analyze(list);
  39.  
  40. shuffle(list);
  41. System.out.println("shuffle one more");
  42. analyze(list);
  43.  
  44. init(list);
  45. shuffle(list);
  46. System.out.println("[new 1000]shuffle");
  47. analyze(list);
  48.  
  49. init(list);
  50. shuffle(list);
  51. System.out.println("[new 1000]shuffle");
  52. analyze(list);
  53.  
  54. for (int i = 0; i < 10; ++i)
  55. {
  56. shuffle(list);
  57. }
  58. System.out.println("shuffle 10 times");
  59. analyze(list);
  60.  
  61. list = new int[3000];
  62. init(list);
  63. shuffle(list);
  64. System.out.println("[new 3000]shuffle");
  65. analyze(list);
  66.  
  67. for (int i = 0; i < 10; ++i)
  68. {
  69. shuffle(list);
  70. }
  71. System.out.println("shuffle 10 times");
  72. analyze(list);
  73.  
  74. for (int j = 0; j < 3; ++j)
  75. {
  76. list = new int[100];
  77. init(list);
  78. shuffle(list);
  79. System.out.println("[new 100]shuffle");
  80. analyze(list);
  81.  
  82. for (int i = 0; i < 10; ++i)
  83. {
  84. shuffle(list);
  85. }
  86. System.out.println("shuffle 10 times");
  87. analyze(list);
  88. }
  89. }
  90.  
  91. static int makeValue(int n)
  92. {
  93. return n / 10;
  94. }
  95.  
  96. static void init(int[] list)
  97. {
  98. for (int i = 0; i < list.length; ++i)
  99. {
  100. list[i] = makeValue(i);
  101. }
  102. }
  103.  
  104. static void show(int[] list)
  105. {
  106. for (int n : list)
  107. {
  108. System.out.print(n + " ");
  109. }
  110. System.out.println();
  111. }
  112.  
  113. static void analyze(int[] list)
  114. {
  115. System.out.println("** analyze **");
  116. int sum = 0;
  117. for (int i = 1; i < list.length; ++i)
  118. {
  119. sum += Math.abs(list[i] - list[i - 1]);
  120. }
  121. double avg = (double)sum / (double)(list.length - 1);
  122. double s2 = 0.0;
  123. for (int i = 1; i < list.length; ++i)
  124. {
  125. double diff = (double)Math.abs(list[i] - list[i - 1]);
  126. s2 += (avg - diff) * (avg - diff);
  127. }
  128. s2 /= (double)(list.length - 1);
  129. System.out.println("diff avg: " + avg);
  130. System.out.println("diff s2: " + s2);
  131.  
  132. int count = 0;
  133. for (int i = 0; i < list.length; ++i)
  134. {
  135. int v = makeValue(i);
  136. if (v == list[i])
  137. {
  138. ++count;
  139. }
  140. }
  141. System.out.println("stay: " + count);
  142.  
  143. int suc = 0;
  144. for (int i = 1; i < list.length; ++i)
  145. {
  146. if (list[i] == list[i - 1])
  147. {
  148. ++suc;
  149. }
  150. }
  151. System.out.println("succeession: " + suc);
  152. }
  153. }
Success #stdin #stdout 0.11s 380544KB
stdin
Standard input is empty
stdout
49 46 59 41 72 37 25 64 18 0 52 32 25 19 47 33 83 47 27 81 8 2 90 73 2 84 42 99 25 15 3 93 8 3 34 99 77 93 68 53 4 87 2 45 22 78 75 38 14 84 18 44 45 32 98 13 31 68 69 86 13 16 83 34 38 14 72 63 68 36 7 53 89 42 28 26 85 7 51 1 48 80 49 21 75 8 9 56 54 3 9 9 98 69 70 12 64 9 79 42 83 98 29 42 99 82 71 98 56 10 40 22 22 91 65 51 59 29 3 31 28 0 2 95 10 33 10 12 66 15 13 16 48 13 95 10 40 1 13 2 93 19 53 14 18 91 34 14 71 14 15 15 29 15 37 65 50 97 95 12 72 41 39 97 30 69 80 88 94 16 43 83 17 65 70 12 60 17 7 47 0 92 72 5 8 0 4 97 57 18 82 58 19 22 91 34 84 60 81 57 22 16 57 5 26 45 48 20 57 24 50 95 49 45 21 26 58 61 21 39 13 95 46 86 60 21 18 62 38 50 94 52 11 52 66 54 60 88 34 30 76 49 20 21 24 93 20 6 24 41 49 12 89 25 25 30 40 82 76 65 52 46 94 1 67 24 63 87 26 87 53 39 30 97 67 70 85 62 83 72 65 25 28 96 35 67 47 76 48 87 85 89 6 50 3 29 8 40 52 64 17 23 59 11 24 26 27 75 69 16 31 80 88 4 31 7 81 6 1 64 5 29 66 70 52 68 28 32 36 94 71 7 1 57 79 33 54 37 70 35 17 68 97 66 72 81 11 76 14 79 91 35 35 7 67 35 91 35 87 27 57 4 26 19 6 19 99 6 26 58 69 78 96 55 61 62 83 37 42 24 38 94 18 36 33 34 37 38 62 30 6 73 96 39 39 4 16 29 4 59 53 41 33 73 98 93 35 40 55 39 80 95 60 74 41 51 41 52 41 74 42 28 44 44 9 23 63 47 30 58 49 11 88 92 60 89 70 79 27 39 43 94 43 86 44 92 56 20 90 44 7 45 18 75 67 28 48 38 63 46 90 46 85 26 62 56 93 17 96 5 47 76 73 40 20 47 43 79 18 84 34 10 36 43 13 49 54 50 48 86 55 12 26 44 76 49 0 49 44 58 41 4 29 66 1 50 10 29 74 85 11 61 35 8 89 53 67 51 51 51 52 85 11 27 52 56 99 17 78 84 99 75 42 77 51 65 67 86 14 98 85 54 0 54 54 79 77 77 88 34 91 80 33 51 85 48 78 45 50 62 6 47 92 56 56 3 10 17 56 93 20 57 37 73 35 65 57 85 67 95 59 7 58 58 72 28 40 61 19 5 59 45 42 54 82 88 88 1 24 12 18 44 60 81 60 78 53 14 60 11 21 9 23 61 73 92 61 61 97 71 45 43 43 19 7 27 62 62 0 62 25 42 37 63 63 2 96 1 65 84 24 23 64 22 8 0 77 64 45 55 4 30 98 65 97 82 66 44 23 57 31 77 35 22 55 84 66 17 65 59 67 25 67 75 80 11 61 92 72 20 19 44 68 86 39 61 64 6 71 82 5 37 32 74 3 36 87 22 9 1 26 23 91 50 69 54 17 5 78 70 45 18 71 20 31 28 74 23 71 32 37 28 76 96 88 71 59 90 99 2 73 71 36 25 93 61 64 73 46 69 23 60 74 74 99 78 49 58 84 10 75 21 30 71 6 62 47 9 75 75 94 99 9 48 76 63 13 96 36 63 13 25 72 99 39 50 34 77 77 33 46 78 3 52 4 31 15 77 74 97 31 89 24 34 79 79 30 20 11 53 92 15 80 89 70 29 43 38 3 80 43 81 55 63 40 91 29 21 76 81 23 82 66 82 28 8 68 82 82 81 55 46 63 2 56 86 78 83 27 3 21 41 87 91 84 55 83 40 73 15 50 64 88 32 27 90 89 10 33 16 46 43 68 86 72 27 86 11 16 74 16 19 15 87 53 42 38 87 56 69 68 51 69 10 88 87 5 0 48 85 38 81 89 48 41 70 36 89 58 19 91 90 70 57 68 90 75 90 54 73 40 32 98 12 23 5 15 8 78 55 0 80 30 92 31 9 66 22 94 92 27 14 93 93 14 58 12 46 33 47 95 94 94 6 32 32 24 59 92 77 20 21 36 39 95 7 90 38 79 22 83 55 17 76 51 13 96 80 1 96 84 97 74 2 79 37 69 98 83 95 96 53 31 8 32 97 98 64 59 66 33 5 90 12 4 16 2 86 81 36 
[new 1000]shuffle
** analyze **
diff avg: 32.525525525525524
diff s2: 561.4105096087075
stay: 147
succeession: 26
shuffle one more
** analyze **
diff avg: 33.44144144144144
diff s2: 541.1674918161406
stay: 38
succeession: 9
[new 1000]shuffle
** analyze **
diff avg: 32.43843843843844
diff s2: 540.9028668307952
stay: 145
succeession: 32
[new 1000]shuffle
** analyze **
diff avg: 32.33833833833834
diff s2: 559.1588004420832
stay: 150
succeession: 26
shuffle 10 times
** analyze **
diff avg: 32.851851851851855
diff s2: 572.460534608682
stay: 9
succeession: 13
[new 3000]shuffle
** analyze **
diff avg: 97.8972990996999
diff s2: 5086.683683935525
stay: 438
succeession: 72
shuffle 10 times
** analyze **
diff avg: 98.0646882294098
diff s2: 5090.069173218908
stay: 15
succeession: 7
[new 100]shuffle
** analyze **
diff avg: 3.121212121212121
diff s2: 5.460055096418732
stay: 21
succeession: 9
shuffle 10 times
** analyze **
diff avg: 3.4444444444444446
diff s2: 5.96408529741863
stay: 11
succeession: 5
[new 100]shuffle
** analyze **
diff avg: 3.121212121212121
diff s2: 5.500459136822774
stay: 20
succeession: 13
shuffle 10 times
** analyze **
diff avg: 3.242424242424242
diff s2: 4.8503213957759375
stay: 7
succeession: 7
[new 100]shuffle
** analyze **
diff avg: 2.95959595959596
diff s2: 5.372104887256397
stay: 26
succeession: 16
shuffle 10 times
** analyze **
diff avg: 3.3333333333333335
diff s2: 5.8585858585858555
stay: 12
succeession: 11