Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class DicesSolution {
- static int[] first = new int[6];
- static int[] second = new int[6];
- static int[] third = new int[6];
- static int maxDiff = Integer.MIN_VALUE;
- static int counter = 1;
- public static void main(String[] args) {
- goForFirst();
- }
- private static void goForFirst() {
- for (first[0] = 1; first[0] < 7; first[0]++) {
- for (first[1] = first[0]; first[1] < 7; first[1]++) {
- for (first[2] = first[1]; first[2] < 7; first[2]++) {
- for (first[3] = first[2]; first[3] < 7; first[3]++) {
- for (first[4] = first[3]; first[4] < 7; first[4]++) {
- for (first[5] = first[4]; first[5] < 7; first[5]++) {
- goForSecond();
- }
- }
- }
- }
- }
- }
- }
- private static void goForSecond() {
- for (second[0] = 1; second[0] < 7; second[0]++) {
- for (second[1] = second[0]; second[1] < 7; second[1]++) {
- for (second[2] = second[1]; second[2] < 7; second[2]++) {
- for (second[3] = second[2]; second[3] < 7; second[3]++) {
- for (second[4] = second[3]; second[4] < 7; second[4]++) {
- for (second[5] = second[4]; second[5] < 7; second[5]++) {
- goForThird();
- }
- }
- }
- }
- }
- }
- }
- private static void goForThird() {
- int res12 = compare(first, second);
- for (third[0] = 1; third[0] < 7; third[0]++) {
- for (third[1] = third[0]; third[1] < 7; third[1]++) {
- for (third[2] = third[1]; third[2] < 7; third[2]++) {
- for (third[3] = third[2]; third[3] < 7; third[3]++) {
- for (third[4] = third[3]; third[4] < 7; third[4]++) {
- for (third[5] = third[4]; third[5] < 7; third[5]++) {
- int res23 = compare(second, third);
- int res31 = compare(third, first);
- if ((res12 > 0 && res23 > 0 && res31 > 0)) {
- int currMinDiff = Math.min(Math.min(res12, res23), res31);
- maxDiff = Math.max(currMinDiff, maxDiff);
- System.out.println(
- new StringBuilder("Solution #")
- .append(counter++)
- .append(" with diff ")
- .append(currMinDiff)
- .append(" is ")
- .append(Arrays.toString(first))
- .append(", ")
- .append(Arrays.toString(second))
- .append(", ")
- .append(Arrays.toString(third))
- .toString());
- }
- }
- }
- }
- }
- }
- }
- }
- private static int compare(int[] first, int[] second) {
- int result = 0;
- for (int i = 0; i < first.length; i++) {
- for (int j = 0; j < second.length; j++) {
- if (first[i] > second[j]) result++;
- else result--;
- }
- }
- return result;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement