fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4.  
  5. class Ideone
  6. {
  7. // boolean sorted(Integer[] n,int i){while(i-->1)if(n[i]<n[i-1])return false;return true;}void bogo(Integer[] n){List<Integer>l=Arrays.asList(n);while(!sorted(n,n.length)){Collections.shuffle(l);l.toArray(n);}}
  8.  
  9. public static
  10. boolean sorted(Integer[] n,int i)
  11. {
  12. while(i --> 1) // i..1
  13. if(n[i] < n[i-1]) // ascending order
  14. return false;
  15.  
  16. return true;
  17. }
  18.  
  19. public static
  20. void bogo(Integer[] n)
  21. {
  22. List<Integer>l = Arrays.asList(n);
  23.  
  24. while(!sorted(n, n.length))
  25. {
  26. Collections.shuffle(l); // shuffle
  27. l.toArray(n); // re-fill the array
  28. }
  29. }
  30.  
  31. public static void main(String[] args) throws java.lang.Exception
  32. {
  33. Integer[] a = { 3, 5, 1, 7, 4, 0, -2 };
  34. bogo(a);
  35. for(Integer x : a) System.out.print(x+" ");
  36. }
  37. }
Success #stdin #stdout 0.1s 320576KB
stdin
Standard input is empty
stdout
-2 0 1 3 4 5 7