This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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