Create a gist now

Instantly share code, notes, and snippets.

@hc5 /test.java
Created Dec 10, 2012

Embed
What would you like to do?
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