From c64f0360a669b638238f4a470553f448ca8956ff Mon Sep 17 00:00:00 2001 From: Mart Lubbers Date: Mon, 13 Dec 2021 08:19:19 +0100 Subject: [PATCH] fix 12b --- 12b.c | 18 +++++++++++++----- Makefile | 3 +++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/12b.c b/12b.c index 5be7962..38aaf41 100644 --- a/12b.c +++ b/12b.c @@ -51,10 +51,15 @@ char **copy_visited(char **visited, int nvisited) return r; } -int find_end(struct node *node, char **visited, int nvisited, bool twice) +int find_end(struct node *node, char **visited, int nvisited, bool twice, char **path, int npath) { - if (strcmp(node->key, "end") == 0) + if (strcmp(node->key, "end") == 0) { + printf("path: "); + for (int i = 0; ikey[0])) { for (int i = 0; ikey, visited[i]) == 0) @@ -62,11 +67,13 @@ int find_end(struct node *node, char **visited, int nvisited, bool twice) visited = realloc(visited, sizeof(char *)*(nvisited+1)); visited[nvisited++] = node->key; } + path = realloc(path, sizeof(char *)*(npath+1)); + path[npath++] = node->key; int r = 0; for (struct conn *c = node->connections; c != NULL; c = c->hh.next) { if (twice && strcmp(node->key, "start") != 0 && islower(node->key[0])) - r += find_end(c->node, copy_visited(visited, nvisited-1), nvisited-1, false); - r += find_end(c->node, copy_visited(visited, nvisited), nvisited, twice); + r += find_end(c->node, copy_visited(visited, nvisited-1), nvisited-1, false, copy_visited(path, npath), npath); + r += find_end(c->node, copy_visited(visited, nvisited), nvisited, twice, copy_visited(path, npath), npath); } free(visited); return r; @@ -86,5 +93,6 @@ int main() get_or_create(&graph, toname)); } - printf("%d\n", find_end(get_or_create(&graph, "start"), NULL, 0, true)); + find_end(get_or_create(&graph, "start"), NULL, 0, true, NULL, 0); +// printf("%d\n", find_end(get_or_create(&graph, "start"), NULL, 0, true, NULL, 0)); } diff --git a/Makefile b/Makefile index e656642..50c1a9f 100644 --- a/Makefile +++ b/Makefile @@ -13,6 +13,9 @@ clean: run: $(addprefix run_,$(BINARIES)) +run_12b: 12b + ./12b < 12.txt | sort -u | wc -l + run_%a: %a ./$< < $*.txt -- 2.20.1