diff options
author | Marvin Borner | 2020-12-15 19:05:15 +0100 |
---|---|---|
committer | Marvin Borner | 2020-12-15 19:05:15 +0100 |
commit | ef77ab8321666aaab61a05c91cf789e6ab41e538 (patch) | |
tree | 29c334c270564eab618faed862c15e58078b6ce8 | |
parent | 19b79a9708966ce59d55f202f47ed7bc9aebaac0 (diff) |
Small improvement ig
-rw-r--r-- | 2020/15/solve.c | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/2020/15/solve.c b/2020/15/solve.c index a3406f0..c6b9591 100644 --- a/2020/15/solve.c +++ b/2020/15/solve.c @@ -26,7 +26,7 @@ int add(struct num **nums, int index, int num) return diff; } -int calc(FILE *fp, int count) +void calc(FILE *fp) { struct num *nums = NULL; @@ -34,10 +34,13 @@ int calc(FILE *fp, int count) while (fscanf(fp, "%d,", &num) == 1) num = add(&nums, index++, num); - while (index < count) + while (index < 2020) num = add(&nums, index++, num); + printf("%d\n", num); - return num; + while (index < 30000000) + num = add(&nums, index++, num); + printf("%d\n", num); } int main(int argc, char *argv[]) @@ -47,9 +50,7 @@ int main(int argc, char *argv[]) exit(EXIT_FAILURE); clock_t tic = clock(); - printf("%d\n", calc(fp, 2020)); - rewind(fp); - printf("%d\n", calc(fp, 30000000)); + calc(fp); clock_t toc = clock(); printf("TIME: %f seconds\n", (double)(toc - tic) / CLOCKS_PER_SEC); |