fork 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 = i;
  17. int b = rand.nextInt(list.length - i) + i;
  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.  
  75. for (int j = 0; j < 3; ++j)
  76. {
  77. list = new int[100];
  78. init(list);
  79. shuffle(list);
  80. System.out.println("[new 100]shuffle");
  81. analyze(list);
  82.  
  83. for (int i = 0; i < 10; ++i)
  84. {
  85. shuffle(list);
  86. }
  87. System.out.println("shuffle 10 times");
  88. analyze(list);
  89. }
  90. }
  91.  
  92. static int makeValue(int n)
  93. {
  94. return n / 10;
  95. }
  96.  
  97. static void init(int[] list)
  98. {
  99. for (int i = 0; i < list.length; ++i)
  100. {
  101. list[i] = makeValue(i);
  102. }
  103. }
  104.  
  105. static void show(int[] list)
  106. {
  107. for (int n : list)
  108. {
  109. System.out.print(n + " ");
  110. }
  111. System.out.println();
  112. }
  113.  
  114. static void analyze(int[] list)
  115. {
  116. System.out.println("** analyze **");
  117. int sum = 0;
  118. for (int i = 1; i < list.length; ++i)
  119. {
  120. sum += Math.abs(list[i] - list[i - 1]);
  121. }
  122. double avg = (double)sum / (double)(list.length - 1);
  123. double s2 = 0.0;
  124. for (int i = 1; i < list.length; ++i)
  125. {
  126. double diff = (double)Math.abs(list[i] - list[i - 1]);
  127. s2 += (avg - diff) * (avg - diff);
  128. }
  129. s2 /= (double)(list.length - 1);
  130. System.out.println("diff avg: " + avg);
  131. System.out.println("diff s2: " + s2);
  132.  
  133. int count = 0;
  134. for (int i = 0; i < list.length; ++i)
  135. {
  136. int v = makeValue(i);
  137. if (v == list[i])
  138. {
  139. ++count;
  140. }
  141. }
  142. System.out.println("stay: " + count);
  143.  
  144. int suc = 0;
  145. for (int i = 1; i < list.length; ++i)
  146. {
  147. if (list[i] == list[i - 1])
  148. {
  149. ++suc;
  150. }
  151. }
  152. System.out.println("succeession: " + suc);
  153. }
  154. }
Success #stdin #stdout 0.11s 380480KB
stdin
Standard input is empty
stdout
52 57 98 84 99 98 39 8 64 66 96 50 19 28 67 8 34 18 29 67 87 23 58 7 25 51 35 59 43 80 54 40 2 36 88 32 34 21 90 32 8 92 46 45 91 7 67 13 86 86 8 79 16 7 38 43 36 72 18 39 9 73 54 39 69 47 6 70 56 31 61 68 32 35 68 22 4 10 13 76 33 93 64 35 56 14 2 71 75 32 44 99 78 0 5 91 15 83 11 50 28 94 29 94 16 43 17 85 50 39 51 5 48 35 74 8 75 77 21 82 45 23 32 96 9 58 89 52 75 83 44 75 29 69 98 1 56 6 16 91 5 81 56 47 63 42 8 51 0 56 37 71 1 21 83 95 88 84 70 78 23 21 66 38 92 64 38 12 30 27 3 87 99 15 69 90 27 14 73 1 54 36 86 49 56 93 87 11 73 76 52 27 2 33 49 54 71 1 90 60 36 26 53 47 19 21 64 92 88 92 55 39 59 69 53 28 20 40 5 86 83 28 2 64 2 76 80 66 87 85 62 53 41 3 67 33 28 90 27 6 94 38 94 84 38 58 63 3 9 82 80 64 20 73 97 59 21 49 63 8 54 72 27 37 55 98 89 47 11 54 22 39 71 23 20 7 2 98 61 19 49 23 49 39 54 6 30 24 50 19 28 47 44 47 97 57 29 37 4 41 45 28 45 94 7 10 65 93 82 31 89 42 16 81 81 88 58 25 63 52 45 67 9 89 30 50 32 82 82 54 26 39 42 90 62 16 85 31 90 87 43 75 86 36 26 52 81 38 12 57 99 13 89 34 46 61 33 20 48 80 88 97 36 69 61 91 86 11 15 13 62 96 56 66 11 75 71 9 93 31 1 49 76 89 54 29 15 32 72 21 4 77 77 61 76 57 20 67 73 92 65 85 24 58 61 35 71 92 88 3 42 79 27 18 26 94 16 72 17 70 25 4 1 78 55 64 87 1 26 18 94 58 9 50 72 65 53 8 28 66 22 11 46 59 7 47 86 93 30 19 43 78 97 19 17 7 74 82 13 68 17 84 68 21 4 38 12 78 34 52 24 39 55 92 20 15 41 41 27 95 0 53 2 30 42 6 46 35 59 43 81 45 44 31 0 44 99 52 78 79 34 98 68 6 20 6 90 77 31 33 90 78 76 22 87 71 52 60 35 4 88 63 18 71 97 79 91 96 18 27 13 91 98 10 64 94 3 36 80 74 73 98 19 31 51 96 92 0 88 33 48 68 26 46 85 6 29 84 0 31 26 7 14 31 97 81 10 73 11 70 50 47 76 97 97 3 37 99 42 5 91 83 35 33 77 77 10 96 65 89 52 22 87 25 42 74 70 67 21 24 57 95 67 84 40 4 17 55 24 60 74 96 48 77 22 48 62 99 25 38 73 84 78 18 94 17 23 3 14 80 9 22 15 79 48 51 25 43 24 40 7 40 89 63 97 13 10 66 77 38 42 59 89 99 14 11 48 43 41 76 81 81 44 10 46 5 35 46 68 12 24 6 14 24 95 51 31 62 93 13 42 12 34 25 69 69 17 33 87 11 62 19 75 60 94 78 36 48 40 41 16 8 28 49 12 61 97 57 55 26 63 85 29 61 40 48 83 71 41 57 46 59 65 87 90 72 20 4 12 63 0 37 29 55 50 67 64 93 48 28 81 35 33 96 95 80 15 9 3 60 84 86 93 18 24 76 62 14 1 60 34 59 12 44 4 9 16 59 60 53 23 43 75 20 16 44 61 24 25 32 85 95 44 46 27 80 66 22 74 47 65 73 37 74 75 20 42 53 66 90 49 27 16 2 22 72 55 72 52 51 37 62 65 0 17 36 41 91 58 70 60 2 15 95 62 13 74 56 6 92 60 5 68 0 1 56 49 81 77 95 60 65 2 10 53 95 44 91 82 51 45 86 80 41 83 79 30 25 58 51 19 11 96 89 45 63 1 3 39 18 78 86 70 79 23 61 98 29 93 14 46 10 5 75 37 30 69 82 62 15 57 45 82 55 19 5 13 14 68 56 53 76 69 50 95 72 51 17 40 45 99 77 21 65 41 23 3 5 83 79 84 40 72 58 32 26 64 88 68 70 55 36 30 49 88 73 92 26 65 53 34 96 0 74 12 32 79 67 29 85 85 66 15 34 17 43 59 30 93 22 10 98 9 63 12 58 34 4 18 25 79 37 8 37 57 40 83 69 74 30 66 23 71 57 83 7 47 14 80 50 33 85 91 99 70 84 38 82 54 70 
[new 1000]shuffle
** analyze **
diff avg: 32.712712712712715
diff s2: 529.1537022507994
stay: 8
succeession: 10
shuffle one more
** analyze **
diff avg: 34.63563563563564
diff s2: 574.692063434806
stay: 12
succeession: 7
[new 1000]shuffle
** analyze **
diff avg: 33.272272272272275
diff s2: 570.8888307727154
stay: 5
succeession: 4
[new 1000]shuffle
** analyze **
diff avg: 34.31831831831832
diff s2: 580.9637385132884
stay: 12
succeession: 6
shuffle 10 times
** analyze **
diff avg: 33.048048048048045
diff s2: 562.8024961898839
stay: 9
succeession: 13
[new 3000]shuffle
** analyze **
diff avg: 98.09103034344781
diff s2: 4832.770973229821
stay: 8
succeession: 12
shuffle 10 times
** analyze **
diff avg: 100.6322107369123
diff s2: 5009.1301528652275
stay: 6
succeession: 7
[new 100]shuffle
** analyze **
diff avg: 3.5353535353535355
diff s2: 6.753800632588512
stay: 10
succeession: 9
shuffle 10 times
** analyze **
diff avg: 3.6565656565656566
diff s2: 5.154780124477092
stay: 8
succeession: 6
[new 100]shuffle
** analyze **
diff avg: 3.6464646464646466
diff s2: 6.289154167942048
stay: 10
succeession: 4
shuffle 10 times
** analyze **
diff avg: 3.2626262626262625
diff s2: 5.830017345168859
stay: 8
succeession: 8
[new 100]shuffle
** analyze **
diff avg: 3.3838383838383836
diff s2: 6.0142842567085
stay: 9
succeession: 8
shuffle 10 times
** analyze **
diff avg: 3.6464646464646466
diff s2: 5.359861238649117
stay: 6
succeession: 7