// Pinwheel with idle days. Tasks with periods a[0..n-1]; a state is the slack vector d (0 <= d[i] < a[i]): // d[i] = how many more days task i may wait. One day: serve task j (d[j] := a[j]-1) or idle; every other d[i] drops by 1 // and must stay >= 0. Question: is there an infinite run from the all-fresh state that idles infinitely often? // Buchi condition by nested fixed points on the full state space (no reachability pruning): // X := all states; repeat { Y := least set with: s in Y if (idle(s) in X) or (some serve(s,j) in Y), s in X; X := Y } until stable. #include #include #include typedef unsigned long long u64; int n, a[16]; u64 mul[16], total; int main(int argc, char **argv) { n = argc - 1; total = 1; for (int i = 0; i < n; i++) { a[i] = atoi(argv[i + 1]); mul[i] = total; total *= a[i]; } unsigned char *X = malloc(total), *Y = malloc(total); memset(X, 1, total); int d[16]; for (int round = 1;; round++) { memset(Y, 0, total); u64 ny = 0; int sweeps = 0; for (int changed = 1; changed;) { changed = 0; sweeps++; for (u64 s = 0; s < total; s++) { if (!X[s] || Y[s]) continue; u64 t = s, dec = 0; int ok = 1, zero = -1, nz = 0; for (int i = 0; i < n; i++) { d[i] = t % a[i]; t /= a[i]; if (d[i] == 0) { nz++; zero = i; } dec += mul[i]; } if (nz > 1) continue; // two tasks due today: dead u64 base = s - dec; // all slacks minus one (valid only where d[i] > 0) int good = 0; if (nz == 0 && X[base]) good = 1; // idle today, land in X for (int j = 0; j < n && !good; j++) { if (nz == 1 && j != zero) continue; // the due task must be served u64 v = base + mul[j] * (u64)(a[j] - 1 - d[j] + 1); if (Y[v]) good = 1; } if (good) { Y[s] = 1; ny++; changed = 1; } } } u64 nx = 0; for (u64 s = 0; s < total; s++) nx += X[s]; printf("round %d: X=%llu Y=%llu sweeps=%d\n", round, nx, ny, sweeps); fflush(stdout); if (nx == ny) break; memcpy(X, Y, total); } printf("all-fresh state %s\n", X[total - 1] ? "CAN idle infinitely often" : "CANNOT idle infinitely often"); return 0; }