@Test public void basicTest3Linear() { assertTrue(Reduction.threeLinear(new int[]{16, 8, 3})); assertFalse(Reduction.threeLinear(new int[]{2, 1, -2, -2})); assertTrue(Reduction.threeLinear(new int[]{-7, 16, 8, 3, 6})); assertTrue(Reduction.threeLinear(new int[]{-9, 2, 11, -3, 5, 87})); assertFalse(Reduction.threeLinear(new int[]{4, 2, -4, 4, -4})); assertFalse(Reduction.threeLinear(new int[]{1, -1})); }
public static boolean threeLinear(int[] A) { int max = 0; for (int i : A) { max = Math.max(max, Math.abs(i)); } max = max + 1; int[] newA = new int[2 * A.length]; for (int i = 0; i < A.length; i++) newA[i] = 8 * max + A[i]; for (int i = A.length; i < newA.length; i++) newA[i] = -8 * (A[i - A.length] + 2 * max); return threeSumNotDistinct(newA); }
Reduction { public static boolean threeLinear(int[] A) { int max = 0; for (int i : A) { max = Math.max(max, Math.abs(i)); } max = max + 1; int[] newA = new int[2 * A.length]; for (int i = 0; i < A.length; i++) newA[i] = 8 * max + A[i]; for (int i = A.length; i < newA.length; i++) newA[i] = -8 * (A[i - A.length] + 2 * max); return threeSumNotDistinct(newA); } }
Reduction { public static boolean threeLinear(int[] A) { int max = 0; for (int i : A) { max = Math.max(max, Math.abs(i)); } max = max + 1; int[] newA = new int[2 * A.length]; for (int i = 0; i < A.length; i++) newA[i] = 8 * max + A[i]; for (int i = A.length; i < newA.length; i++) newA[i] = -8 * (A[i - A.length] + 2 * max); return threeSumNotDistinct(newA); }  }
Reduction { public static boolean threeLinear(int[] A) { int max = 0; for (int i : A) { max = Math.max(max, Math.abs(i)); } max = max + 1; int[] newA = new int[2 * A.length]; for (int i = 0; i < A.length; i++) newA[i] = 8 * max + A[i]; for (int i = A.length; i < newA.length; i++) newA[i] = -8 * (A[i - A.length] + 2 * max); return threeSumNotDistinct(newA); }  static boolean threeSum(int[] A); static boolean threeLinear(int[] A); }
Reduction { public static boolean threeLinear(int[] A) { int max = 0; for (int i : A) { max = Math.max(max, Math.abs(i)); } max = max + 1; int[] newA = new int[2 * A.length]; for (int i = 0; i < A.length; i++) newA[i] = 8 * max + A[i]; for (int i = A.length; i < newA.length; i++) newA[i] = -8 * (A[i - A.length] + 2 * max); return threeSumNotDistinct(newA); }  static boolean threeSum(int[] A); static boolean threeLinear(int[] A);  }