Skip to content

Instantly share code, notes, and snippets.

@hc5
Created December 10, 2012 05:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hc5/4248610 to your computer and use it in GitHub Desktop.
Save hc5/4248610 to your computer and use it in GitHub Desktop.
public class Test {
private static final int dim = 100;
static int[][] graph = new int[dim][dim];
static boolean[] color = new boolean[dim];
private static int trials = 1000;
public static void main(String[] args) {
double triCount = 0;
int totalCount = 0;
for (int t = 0; t < trials; t++) {
for (int i = 0; i < dim; i++) {
for (int j = 0; j < dim; j++) {
graph[i][j] = j;
color[i] = (int) (Math.random() * 1000) % 2 == 1;
}
}
for (int i = 0; i < dim; i++) {
for (int j = i + 1; j < dim; j++) {
for (int k = j + 1; k < dim; k++) {
if (t == 0) {
totalCount++;
}
if (tri(i, j, k)) {
triCount += 1;
}
}
}
}
}
triCount /= trials;
System.out.println(totalCount);
System.out.println(triCount);
}
static boolean tri(int a, int b, int c) {
return color[a] == color[b] && color[b] == color[c];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment