Advertisement
Guest User

Untitled

a guest
May 1st, 2016
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. public class Main {
  2.  
  3. public static void main(String[] args) {
  4. int count= 0;
  5. Perm perm = new Perm(3);
  6. int[] d;
  7.  
  8.  
  9. while ((d = perm.getNext()) != null) {
  10. int[]c = d.clone();
  11.  
  12. for(int o=0;o<c.length;o++)
  13. c[o] +=1;
  14.  
  15.  
  16. permLoop:
  17. for (int i = 0; i < c.length - 2; i++) {
  18.  
  19. if (i <= c.length / 2) {
  20. double lr = (((double)c[i] + (double)c[c.length-1 - i]) / 2);
  21.  
  22. if (!containsBet(i, c.length-1 - i, c, lr))
  23. break permLoop;
  24.  
  25. }
  26.  
  27. double l = ((double)c[0] + (double)c[c.length-1 - i]) / 2;
  28. if (!containsBet(0, c.length-1 - i, c, l))
  29. break permLoop;
  30.  
  31.  
  32. double r = ((double)c[i] + (double)c[c.length-1]) / 2;
  33. if (!containsBet(i, c.length-1, c, r))
  34. break permLoop;
  35.  
  36. System.out.println(Arrays.toString(c));
  37. count++;
  38. }
  39.  
  40. }
  41.  
  42. System.out.println(count);
  43.  
  44.  
  45. }
  46.  
  47. public static boolean containsBet(int st,int end,int[] c, double val)
  48. {
  49. for(int j=st+1;j<= end-1;j++)
  50. {
  51. if(c[j]==val)
  52. return false;
  53.  
  54.  
  55.  
  56. }
  57. return true;
  58. }
  59.  
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement