diff options
author | Tomasz Kramkowski <tk@the-tk.com> | 2021-11-25 22:33:45 +0000 |
---|---|---|
committer | Tomasz Kramkowski <tk@the-tk.com> | 2021-11-25 22:33:45 +0000 |
commit | 0e8e49af605d3160645e773fdec53b7cf60cc068 (patch) | |
tree | e6a57463ae610b0be85884c3ee4bc2b6dd927b37 /20 | |
parent | a7a6b86002b595bc167af72606b14c67ed1bdf8f (diff) | |
download | aoc2015-0e8e49af605d3160645e773fdec53b7cf60cc068.tar.gz aoc2015-0e8e49af605d3160645e773fdec53b7cf60cc068.tar.xz aoc2015-0e8e49af605d3160645e773fdec53b7cf60cc068.zip |
more solutions
Diffstat (limited to '20')
-rw-r--r-- | 20/solution.c | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/20/solution.c b/20/solution.c index cf61687..73beb80 100644 --- a/20/solution.c +++ b/20/solution.c @@ -16,9 +16,8 @@ long part1(long input) long *houses = emalloc(sizeof(long) * input / 10); #pragma omp parallel for for (long i = 1; i < input / 10; i++) - for (long j = i; j < input / 10; j++) + for (long j = i; j < input / 10; j += i) houses[j] += i * 10; - puts("filled houses"); for (long i = 1; i < input / 10; i++) { if (houses[i] >= input) { res = i; @@ -31,11 +30,25 @@ long part1(long input) long part2(long input) { - return -1; + long res = -1; + long *houses = emalloc(sizeof(long) * input / 10); + #pragma omp parallel for + for (long i = 1; i < input / 10; i++) + for (long j = i, k = 0; j < input / 10 && k < 50; j += i, k++) + houses[j] += i * 11; + for (long i = 1; i < input / 10; i++) { + if (houses[i] >= input) { + res = i; + break; + } + } + free(houses); + return res; } int main(void) { long input = 33100000; printf("%ld\n", part1(input)); + printf("%ld\n", part2(input)); } |