Advertisement
Guest User

Untitled

a guest
Feb 28th, 2017
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.83 KB | None | 0 0
  1. public class DicesSolution {
  2.     static int[] first = new int[6];
  3.     static int[] second = new int[6];
  4.     static int[] third = new int[6];
  5.     static int maxDiff = Integer.MIN_VALUE;
  6.     static int counter = 1;
  7.  
  8.     public static void main(String[] args) {
  9.         goForFirst();
  10.     }
  11.  
  12.     private static void goForFirst() {
  13.         for (first[0] = 1; first[0] < 7; first[0]++) {
  14.             for (first[1] = first[0]; first[1] < 7; first[1]++) {
  15.                 for (first[2] = first[1]; first[2] < 7; first[2]++) {
  16.                     for (first[3] = first[2]; first[3] < 7; first[3]++) {
  17.                         for (first[4] = first[3]; first[4] < 7; first[4]++) {
  18.                             for (first[5] = first[4]; first[5] < 7; first[5]++) {
  19.                                 goForSecond();
  20.                             }
  21.                         }
  22.                     }
  23.                 }
  24.             }
  25.         }
  26.     }
  27.  
  28.     private static void goForSecond() {
  29.         for (second[0] = 1; second[0] < 7; second[0]++) {
  30.             for (second[1] = second[0]; second[1] < 7; second[1]++) {
  31.                 for (second[2] = second[1]; second[2] < 7; second[2]++) {
  32.                     for (second[3] = second[2]; second[3] < 7; second[3]++) {
  33.                         for (second[4] = second[3]; second[4] < 7; second[4]++) {
  34.                             for (second[5] = second[4]; second[5] < 7; second[5]++) {
  35.                                 goForThird();
  36.                             }
  37.                         }
  38.                     }
  39.                 }
  40.             }
  41.         }
  42.     }
  43.  
  44.     private static void goForThird() {
  45.         int res12 = compare(first, second);
  46.         for (third[0] = 1; third[0] < 7; third[0]++) {
  47.             for (third[1] = third[0]; third[1] < 7; third[1]++) {
  48.                 for (third[2] = third[1]; third[2] < 7; third[2]++) {
  49.                     for (third[3] = third[2]; third[3] < 7; third[3]++) {
  50.                         for (third[4] = third[3]; third[4] < 7; third[4]++) {
  51.                             for (third[5] = third[4]; third[5] < 7; third[5]++) {
  52.                                 int res23 = compare(second, third);
  53.                                 int res31 = compare(third, first);
  54.                                 if ((res12 > 0 && res23 > 0 && res31 > 0)) {
  55.                                     int currMinDiff = Math.min(Math.min(res12, res23), res31);
  56.                                     maxDiff = Math.max(currMinDiff, maxDiff);
  57.  
  58.                                     System.out.println(
  59.                                             new StringBuilder("Solution #")
  60.                                                     .append(counter++)
  61.                                                     .append(" with diff ")
  62.                                                     .append(currMinDiff)
  63.                                                     .append(" is ")
  64.                                                     .append(Arrays.toString(first))
  65.                                                     .append(", ")
  66.                                                     .append(Arrays.toString(second))
  67.                                                     .append(", ")
  68.                                                     .append(Arrays.toString(third))
  69.                                                     .toString());
  70.                                 }
  71.                             }
  72.                         }
  73.                     }
  74.                 }
  75.             }
  76.         }
  77.     }
  78.  
  79.     private static int compare(int[] first, int[] second) {
  80.         int result = 0;
  81.         for (int i = 0; i < first.length; i++) {
  82.             for (int j = 0; j < second.length; j++) {
  83.                 if (first[i] > second[j]) result++;
  84.                 else result--;
  85.             }
  86.         }
  87.         return result;
  88.     }
  89.  
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement