summaryrefslogtreecommitdiff
path: root/alg_l.c
diff options
context:
space:
mode:
authorMatthew Sotoudeh <matthewsot@outlook.com>2022-10-07 12:46:02 -0700
committerMatthew Sotoudeh <matthewsot@outlook.com>2022-10-07 12:46:02 -0700
commitcf87e5f67ae18767b933edb3b1371696f6b1c582 (patch)
treead114627f109778a894b64c1c2bb3c996229072c /alg_l.c
algorithmsHEADmaster
Diffstat (limited to 'alg_l.c')
-rw-r--r--alg_l.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/alg_l.c b/alg_l.c
new file mode 100644
index 0000000..94cd548
--- /dev/null
+++ b/alg_l.c
@@ -0,0 +1,41 @@
+#include <stdlib.h>
+#include <assert.h>
+#include <stdio.h>
+
+int main(int argv, char **argc) {
+ if (argv < 3) {
+ assert(argv > 0);
+ printf("Usage: %s [n] [t]\n", argc[0]);
+ return -1;
+ }
+
+ size_t n = atoi(argc[1]),
+ t = atoi(argc[2]);
+
+ size_t *c = calloc(t + 3, sizeof(*c));
+
+L1_initialize:
+ for (size_t j = 1; j <= t; j++)
+ c[j] = j - 1;
+ c[t + 1] = n;
+ c[t + 2] = 0;
+
+L2_visit:
+ for (size_t j = t; j >= 1; j--)
+ printf("%lu ", c[j]);
+ printf("\n");
+
+L3_find_j:
+ size_t j = 1;
+ while (c[j] + 1 == c[j + 1]) {
+ c[j] = j - 1;
+ j = j + 1;
+ }
+
+L4_maybe_done:
+ if (j > t) return 0;
+
+L5_increase_c_j:
+ c[j] = c[j] + 1;
+ goto L2_visit;
+}
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback