// Larry Coon // "adjacent" is used here to mean two points are on the same line, disregarding any // intervening points; "colinear" is used here to mean all three points are on the same line. import java.util.Arrays; public class Triangle { private static final int[][] adjacent = {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, {0, 2, 3, 4, 5, 6, 7, 8, 9, 10}, {0, 1, 3, 4, 5, 6}, {0, 1, 2, 5, 7, 9}, {0, 1, 2, 6, 7, 8}, {0, 1, 2, 3, 8, 10}, {0, 1, 2, 4, 9, 10}, {0, 1, 3, 4, 8, 9}, {0, 1, 4, 5, 7, 10}, {0, 1, 3, 6, 7, 10}, {0, 1, 5, 6, 8, 9}}; private static final int[][] colinear = {{0, 2, 4, 6}, {0, 3, 7, 9}, {0, 5, 8, 10}, {1, 2, 3, 5}, {1, 4, 7, 8}, {1, 6, 9, 10}}; public static void main(String[] args) { int count = 0; for (int i = 0; i < adjacent.length; i++) for (int j = i+1; j < adjacent.length; j++) { // Is i adjacent to j? if (Arrays.binarySearch(adjacent[i], j) < 0) continue; for (int k = j + 1; k < adjacent.length; k++) { // Is i adjacent to k? if (Arrays.binarySearch(adjacent[i], k) < 0) continue; // Is j adjacent to k? if (Arrays.binarySearch(adjacent[j], k) < 0) continue; // Are all three points on the same line? boolean found = false; for (int l = 0; l < colinear.length; l++) if (Arrays.binarySearch(colinear[l], i) >= 0 && Arrays.binarySearch(colinear[l], j) >= 0 && Arrays.binarySearch(colinear[l], k) >= 0) { found = true; break; } count += (found ? 0 : 1); } } System.out.println(count); } }