Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Main {
- static final int summ = 33;
- static final int max = 21;
- static final int min = 1;
- static final int varcount = 3;
- static final int maxlen = 3 * (max - (summ - max - min)) * (max - (summ - max - min));
- static int[][] array = new int[maxlen][varcount];
- static int cursor = 0;
- public static void main(String[] args) {
- findsumm(0, 0, 0);
- }
- static void findsumm(int a, int b, int c) {
- switch (c) {
- case 0:
- if (a == 0)
- for (int i = min; i < max; i++)
- findsumm(i, 0, 0);
- else if (b == 0)
- for (int i = min; i < max; i++)
- findsumm(a, i, 0);
- else if (c == 0)
- for (int i = min; i < max; i++)
- findsumm(a, b, i);
- break;
- default:
- if ((a + b + c == summ) && checkarray(a, b, c)) {
- array[cursor][0] = a;
- array[cursor][1] = b;
- array[cursor][2] = c;
- cursor++;
- System.out.println(cursor + ": " + a + " + " + b + " + " + c + " = " + summ);
- }
- break;
- }
- }
- static boolean checkarray(int a, int b, int c) {
- boolean t = true;
- t = t & check(a, b, c);
- t = t & check(a, c, b);
- t = t & check(b, a, c);
- t = t & check(b, c, a);
- t = t & check(c, a, b);
- t = t & check(c, b, a);
- return t;
- }
- static boolean check(int a, int b, int c) {
- for (int i = 0; i < cursor; i++)
- if ((array[i][0] == a) & (array[i][1] == b) & (array[i][2] == c))
- return false;
- return true;
- }
- }
Add Comment
Please, Sign In to add comment