#include void calculate_distribution(int nr_pieces, int length, int nr_holes, int *holes, double *results) { bool h[30]; for (int i = 0; i < length; i++) h[i] = false; for (int i = 0; i < nr_holes; i++) h[holes[i]-1] = true; double s[7][30]; for (int i = 0; i < nr_pieces; i++) for (int j = 0; j < length; j++) s[i][j] = 0.0; s[0][0] = 1.0; bool changed = true; for (int step = 0; step < 200; step++) { for (int i = nr_pieces-1; i >= 0; i--) for (int j = length-2; j >= 0; j--) if (s[i][j] != 0) { double v = s[i][j] / 6; s[i][j] = 0.0; for (int d = 1; d <= 6; d++) if (d+j < length) { if (h[d+j]) { if (i < nr_pieces-1) s[i+1][0] += v; } else s[i][d+j] += v; } else s[i][length-1] += v; } double sum = 0; for (int i = 0; i < nr_pieces; i++) sum += s[i][length-1]; results[step] = sum; } } void compare_distributions(double *a, double *b) { double max_a = a[199]; double max_b = b[199]; double win_a = max_a * (1 - max_b); double win_b = max_b * (1 - max_a); double equal = 0.0; double undecided = (1 - max_a) * (1 - max_b); printf("%20.15lf %20.15lf %20.15lf %20.15lf = %20.15lf\n", win_a, win_b, equal, undecided, win_a + win_b + equal + undecided); for (int i = 1; i < 200; i++) { double v = a[i] - a[i-1]; if (v > 0.0) { win_a += v * (max_b - b[i]); equal += v * (b[i] - b[i-1]); win_b += v * (b[i-1]); } } printf("%20.15lf %20.15lf %20.15lf %20.15lf = %20.15lf\n\n", win_a, win_b, equal, undecided, win_a + win_b + equal + undecided); } int main(int argc, char *argv[]) { int holes_short[] = { 3, 7, 9, 14, 17, 20, 23, 27 }; double results_short[200]; calculate_distribution(7, 28, 8, holes_short, results_short); int holes_long[] = { 2, 6, 12, 14, 18, 21, 24, 28 }; double results_long[200]; calculate_distribution(7, 30, 8, holes_long, results_long); for (int i = 0; i < 200; i++) { printf("%20.15lf %20.15lf", results_short[i], results_long[i]); if (i > 0) printf(" %20.15lf %20.15lf", results_short[i] - results_short[i-1], results_long[i] - results_long[i-1]); printf("\n"); } compare_distributions(results_short, results_long); return 1; };