#include #include #include #define MAX(A, B) (((A) > (B)) ? (A) : (B)) int main(int argv, char **argc) { if (argv < 3) { assert(argv > 0); printf("Usage: %s [n] [t]\n", argc[0]); return -1; } long n = atoi(argc[1]), t = atoi(argc[2]), s = n - t; assert(1 < t && t < n); char *a = calloc(n, sizeof(*a)), *w = calloc(n + 1, sizeof(*a)); C1_initialize: for (size_t j = 0; j < s; j++) a[j] = 0; for (size_t j = s; j < n; j++) a[j] = 1; for (size_t j = 0; j <= n; j++) w[j] = 1; size_t r = (s > 0) ? s : t; C2_visit: for (size_t k = n; k --> 0;) printf("%lu", a[k]); printf("\n"); C3_find_j_and_branch: size_t j = r; while (w[j] == 0) { w[j] = 1; j = j + 1; } if (j == n) return 0; w[j] = 0; if (j % 2 == 1 && a[j] != 0) goto C4_move_right_one; if (j % 2 == 0 && a[j] != 0) goto C5_move_right_two; if (j % 2 == 0 && a[j] == 0) goto C6_move_left_one; if (j % 2 == 1 && a[j] == 0) goto C7_move_left_two; C4_move_right_one: a[j - 1] = 1; a[j] = 0; if (r == j && j > 1) r = j - 1; else if (r == j - 1) r = j; goto C2_visit; C5_move_right_two: if (a[j - 2] != 0) goto C4_move_right_one; a[j - 2] = 1; a[j] = 0; if (r == j) r = MAX(j - 2, 1); else if (r == j - 2) r = j - 1; goto C2_visit; C6_move_left_one: a[j] = 1; a[j - 1] = 0; if (r == j && j > 1) r = j - 1; else if (r == j - 1) r = j; goto C2_visit; C7_move_left_two: if (a[j - 1] != 0) goto C6_move_left_one; a[j] = 1; a[j - 2] = 0; if (r == j - 2) r = j; else if (r == j - 1) r = j - 2; goto C2_visit; }