Skip to content

Instantly share code, notes, and snippets.

@Glorfindel83
Last active October 8, 2020 14:23
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 Glorfindel83/1fa83139b4371114cfcf65915c4a9233 to your computer and use it in GitHub Desktop.
Save Glorfindel83/1fa83139b4371114cfcf65915c4a9233 to your computer and use it in GitHub Desktop.
package nl.magnus.test;
public class Dilemma {
public static void main(String[] args) throws Exception {
for (N = 2; N <= 10; N++) {
graph = new int[N];
ties = 0;
noTies = 0;
iterate(0);
System.out.println("N = " + N + " ties: " + ties + ", no ties: " + noTies + ", ratio: "
+ ((double)ties / (ties + noTies)));
}
}
private static int[] graph;
private static int N;
private static long ties, noTies;
private static void iterate(int n) {
for (int i = 0; i < N; i++) {
if (i == n)
continue;
graph[n] = i;
if (n == N - 1) {
int[] inverse = new int[N];
for (int g : graph) {
inverse[g]++;
}
int max = -1;
boolean tie = false;
for (int g : inverse) {
if (g == max) {
tie = true;
} else if (g > max) {
max = g;
tie = false;
}
}
if (tie) {
ties++;
} else {
noTies++;
}
} else {
iterate(n + 1);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment