From 76d15b25ae8177f3f215552c7be52f26dcec10da Mon Sep 17 00:00:00 2001 From: Adam Spragg Date: Wed, 14 Dec 2022 09:47:05 +0000 Subject: Compare the lists of each node, not each node. Because we're storing the input lists *as a list*, when we compare successive pairs of lists, we can't compare the list nodes themselves. Instead, we compare the lists they point to. Unfortunately, this doesn't change the answer we get. It does improve runtime though! --- 13.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to '13.c') diff --git a/13.c b/13.c index 5bee612..9d876b6 100644 --- a/13.c +++ b/13.c @@ -226,12 +226,12 @@ main() for (n = packets, i = 1; n != NULL && n->next != NULL; n = n->next->next, ++i) { int j; - if ((j = node_cmp(n, n->next)) < 0) { + if ((j = node_cmp(n->val_list, n->next->val_list)) < 0) { index_sum += i; } #if 1 - node_dump(n); fputc('\n', stderr); - node_dump(n->next); fputc('\n', stderr); + node_dump(n->val_list); fputc('\n', stderr); + node_dump(n->next->val_list); fputc('\n', stderr); fprintf(stderr, "Result: %d (%s)\n", j, j < 0 ? "yes" : "no"); #endif -- cgit v1.2.1