aboutsummaryrefslogtreecommitdiff
path: root/2020/15
diff options
context:
space:
mode:
authorThomas Voss <thomasvoss@live.com> 2021-10-29 23:02:39 +0200
committerThomas Voss <thomasvoss@live.com> 2021-10-29 23:02:39 +0200
commite7c9108b95e39d7ea5a29ae06d619c4727f11027 (patch)
tree237261eef3afd0720be77dbcbb9599fa66a24b67 /2020/15
Initial commit
Diffstat (limited to '2020/15')
-rw-r--r--2020/15/.gitignore1
-rw-r--r--2020/15/Makefile7
-rw-r--r--2020/15/puzzles.c31
3 files changed, 39 insertions, 0 deletions
diff --git a/2020/15/.gitignore b/2020/15/.gitignore
new file mode 100644
index 0000000..60d075d
--- /dev/null
+++ b/2020/15/.gitignore
@@ -0,0 +1 @@
+puzzle-[12]
diff --git a/2020/15/Makefile b/2020/15/Makefile
new file mode 100644
index 0000000..c32dafa
--- /dev/null
+++ b/2020/15/Makefile
@@ -0,0 +1,7 @@
+all:
+ ${CC} ${CFLAGS} -o puzzle-1 puzzles.c
+ ${CC} ${CFLAGS} -DPART2 -o puzzle-2 puzzles.c
+
+.PHONY: clean
+clean:
+ rm -f puzzle-[12]
diff --git a/2020/15/puzzles.c b/2020/15/puzzles.c
new file mode 100644
index 0000000..64d89bb
--- /dev/null
+++ b/2020/15/puzzles.c
@@ -0,0 +1,31 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+#ifndef PART2
+ #define BUFFER 2020
+#else
+ #define BUFFER 30000000
+#endif
+
+int
+main(void)
+{
+ /* Given starting numbers */
+ static unsigned int nums[BUFFER] = {0};
+ nums[6] = 1;
+ nums[19] = 2;
+ nums[0] = 3;
+ nums[5] = 4;
+ nums[7] = 5;
+ nums[13] = 6;
+
+ unsigned int temp, lnum = 1;
+ for (int i = 8; i <= BUFFER; i++) {
+ temp = lnum;
+ lnum = nums[lnum] ? i - 1 - nums[lnum] : 0;
+ nums[temp] = i - 1;
+ }
+
+ printf("%u\n", lnum);
+ return EXIT_SUCCESS;
+}