summaryrefslogtreecommitdiffstats
path: root/20
diff options
context:
space:
mode:
authorTomasz Kramkowski <tk@the-tk.com>2021-11-24 22:25:42 +0000
committerTomasz Kramkowski <tk@the-tk.com>2021-11-24 22:25:42 +0000
commita7a6b86002b595bc167af72606b14c67ed1bdf8f (patch)
treebff94329cf969bd9df68d3b9782fee2107db56c2 /20
downloadaoc2015-a7a6b86002b595bc167af72606b14c67ed1bdf8f.tar.gz
aoc2015-a7a6b86002b595bc167af72606b14c67ed1bdf8f.tar.xz
aoc2015-a7a6b86002b595bc167af72606b14c67ed1bdf8f.zip
init commit
Diffstat (limited to '20')
-rw-r--r--20/input1
-rw-r--r--20/solution.c41
2 files changed, 42 insertions, 0 deletions
diff --git a/20/input b/20/input
new file mode 100644
index 0000000..282bc62
--- /dev/null
+++ b/20/input
@@ -0,0 +1 @@
+33100000
diff --git a/20/solution.c b/20/solution.c
new file mode 100644
index 0000000..cf61687
--- /dev/null
+++ b/20/solution.c
@@ -0,0 +1,41 @@
+#include <math.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+void *emalloc(size_t s)
+{
+ void *p = malloc(s);
+ if (p != NULL) return p;
+ fprintf(stderr, "Ran out of memory allocating a buffer of size %zu\n", s);
+ exit(EXIT_FAILURE);
+}
+
+long part1(long input)
+{
+ 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; j < input / 10; j++)
+ houses[j] += i * 10;
+ puts("filled houses");
+ for (long i = 1; i < input / 10; i++) {
+ if (houses[i] >= input) {
+ res = i;
+ break;
+ }
+ }
+ free(houses);
+ return res;
+}
+
+long part2(long input)
+{
+ return -1;
+}
+
+int main(void)
+{
+ long input = 33100000;
+ printf("%ld\n", part1(input));
+}