fork download
  1. import java.util.*;
  2.  
  3. /**
  4.  * To investigate a suggested game theory KotH.
  5.  * For all six-sided dice which are partitions of 21, draw up a "who beats whom" graph.
  6.  */
  7. class NonTransitiveDice {
  8. private static String BASE22 = "0123456789ABCDEFGHIJKL";
  9. private static int MIN = 1;
  10. private static int MAX = 6;
  11.  
  12. public static void main(String[] args) {
  13. Set<String> dice = new HashSet<String>();
  14. for (int a = MIN; a <= MAX; a++) {
  15. for (int b = a; b <= MAX; b++) {
  16. for (int c = b; c <= MAX; c++) {
  17. for (int d = c; d <= MAX; d++) {
  18. for (int e = d; e <= MAX; e++) {
  19. int f = 21 - a - b - c - d - e;
  20. if (f >= e && f <= MAX) {
  21. dice.add(BASE22.charAt(a) + "" +
  22. BASE22.charAt(b) + "" +
  23. BASE22.charAt(c) + "" +
  24. BASE22.charAt(d) + "" +
  25. BASE22.charAt(e) + "" +
  26. BASE22.charAt(f));
  27. }
  28. }
  29. }
  30. }
  31. }
  32. }
  33.  
  34. System.out.println("WW\tWD\tWL\tDW\tDD\tDL\tLW\tLD\tLL\tDie");
  35. for (String d1 : dice) {
  36. int ww = 0, wd = 0, wl = 0, dw = 0, dd = 0, dl = 0, lw = 0, ld = 0, ll = 0;
  37. for (String d2 : dice) {
  38. int c1 = cmp(d1, d2); // 1 => win
  39. int c2 = cmp2(d1, d2);
  40.  
  41. switch (3 * c1 + c2) {
  42. case -4: ll++; break;
  43. case -3: ld++; break;
  44. case -2: lw++; break;
  45.  
  46. case -1: dl++; break;
  47. case 0: dd++; break;
  48. case 1: dw++; break;
  49.  
  50. case 2: wl++; break;
  51. case 3: wd++; break;
  52. case 4: ww++; break;
  53. }
  54. }
  55. System.out.format("%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%s\n", ww,wd,wl, dw,dd,dl, lw,ld,ll , d1);
  56. }
  57. }
  58.  
  59. private static int cmp(String d1, String d2) {
  60. int w1 = 0, w2 = 0;
  61. for (char c1 : d1.toCharArray()) {
  62. for (char c2 : d2.toCharArray()) {
  63. if (c1 > c2) w1++;
  64. if (c2 > c1) w2++;
  65. }
  66. }
  67. return w1 > w2 ? 1 : w1 == w2 ? 0 : -1;
  68. }
  69.  
  70. private static int cmp2(String d1, String d2) {
  71. int[] pair1 = new int[d1.length() * d1.length()];
  72. int[] pair2 = new int[d2.length() * d2.length()];
  73.  
  74. int i = 0;
  75. for (char c1 : d1.toCharArray()) {
  76. for (char c2 : d1.toCharArray()) {
  77. pair1[i++] = BASE22.indexOf(c1) + BASE22.indexOf(c2);
  78. }
  79. }
  80. i = 0;
  81. for (char c1 : d2.toCharArray()) {
  82. for (char c2 : d2.toCharArray()) {
  83. pair2[i++] = BASE22.indexOf(c1) + BASE22.indexOf(c2);
  84. }
  85. }
  86.  
  87. int w1 = 0, w2 = 0;
  88. for (int p1 : pair1) {
  89. for (int p2 : pair2) {
  90. if (p1 > p2) w1++;
  91. if (p2 > p1) w2++;
  92. }
  93. }
  94. return w1 > w2 ? 1 : w1 == w2 ? 0 : -1;
  95. }
  96. }
Success #stdin #stdout 0.12s 380544KB
stdin
Standard input is empty
stdout
WW	WD	WL	DW	DD	DL	LW	LD	LL	Die
13	1	1	2	1	0	6	0	8	234444
5	0	3	3	10	3	3	0	5	113466
3	0	5	2	12	2	5	0	3	222555
12	0	4	5	1	1	4	0	5	113556
10	1	0	0	10	0	0	1	10	133446
4	0	7	0	2	4	3	0	12	222456
3	0	9	0	3	3	2	0	12	333336
11	0	0	0	10	0	0	0	11	233445
6	0	4	0	2	5	1	1	13	123366
3	0	6	0	2	8	0	0	13	233346
13	0	0	8	2	0	6	0	3	134445
7	0	3	0	2	5	0	0	15	223356
6	0	5	3	1	3	2	0	12	133356
12	0	2	3	1	3	5	0	6	124446
13	1	2	3	2	1	2	1	7	224445
4	0	4	3	10	3	4	0	4	223455
5	0	6	0	10	0	6	0	5	112566
8	0	6	0	1	2	1	1	13	333345
5	0	3	2	12	2	3	0	5	111666
5	0	4	1	2	4	0	0	16	223446
16	1	1	1	1	0	5	0	7	114555
16	0	0	4	2	1	4	0	5	133455
7	0	5	0	1	1	1	1	16	222366
7	1	2	1	2	3	2	1	13	233355
0	0	0	11	10	11	0	0	0	123456
13	1	1	5	2	0	4	0	6	114456
5	1	5	0	10	0	5	1	5	122556
8	1	2	0	10	0	2	1	8	333444
12	0	2	3	3	0	9	0	3	144444
12	0	3	4	2	0	7	0	4	123555
5	0	4	1	1	5	4	0	12	122466
15	0	0	5	2	0	3	0	7	124455