aboutsummaryrefslogtreecommitdiff
path: root/2016
diff options
context:
space:
mode:
Diffstat (limited to '2016')
-rw-r--r--2016/02/.gitignore1
-rw-r--r--2016/02/Makefile1
-rw-r--r--2016/02/input5
-rw-r--r--2016/02/puzzles.c60
4 files changed, 67 insertions, 0 deletions
diff --git a/2016/02/.gitignore b/2016/02/.gitignore
new file mode 100644
index 0000000..60d075d
--- /dev/null
+++ b/2016/02/.gitignore
@@ -0,0 +1 @@
+puzzle-[12]
diff --git a/2016/02/Makefile b/2016/02/Makefile
new file mode 100644
index 0000000..de3f940
--- /dev/null
+++ b/2016/02/Makefile
@@ -0,0 +1 @@
+include ../../Makefiles/c.mk
diff --git a/2016/02/input b/2016/02/input
new file mode 100644
index 0000000..68cea45
--- /dev/null
+++ b/2016/02/input
@@ -0,0 +1,5 @@
+LLLUDRDLLULDUDLLRLUDURULDURRRRLLURLDLDDDULLDDUDLRDLRDUURRDUUDLLRUUDDLULURDLRDUUDUDRURULLLLDRULDDLRDDRDLRDDLURLDDUDLLUUDLRDDDDLULUUURRDLUUDDLULLURRRDULLUDUDRDRDDRLDLLRLRDDDRDLULLUULDLLLRRDDUURUURDLLDRRDDLRULDLLDRLLUDRRDLUUULDLURLLDDURRUULLLLLRLUDLDDLLLURRRDUDULRULULDDLLDLRDDDUULRLRDUURLURRUDDURRUUDUDLDDLDULDDDDDULRULRDLRLDLRDLDDLUDRDUUDLDUDUDLLLRLUUDRUDDDRDRURRLLLDLUULDUULRDLULLUURLDRRRLDRLUDRRURLDULULDRUDDULLLDRDLLULUDDDDRDRULDULRRRRDDRULDLRDU
+DLDDRRDLLDUURRLULLLLRDRLUDURLDRRDURRRRUUDDUDRRDDDRRLDDLDDLURDLDRLUDULDUDUUDDDLLULRRLLUDULLLUULDDRDDUDUUDULURULULLDRLRUURDRDDLRRUDRUULLLLURRUDRDULDDRURRURLLLLLRLLLRLLUDUDLRDLULDUDLULLLUUDLLDDDUDUDLLRRDLRDLLLRRLRUDRDUDRURLUUURULLDDDDLLURDULURRLLLRLRRULLRRRLUUULLLLRLRDUURRDUURLLLDRDURRRULDDUDRRDLRLDLLRUDDLLUDRLLUUDRLLLLLLUDLURLLRUDRUUUULDLUDULLDDDDRLURUURDDDURRRLRLUDUUDURDDDDRRLRDLURDDLLULDRDDURLLURULUUUUURDUUULDRRLLURRRRRLDDUULLRULLDLDLDLRRRDRLDRUUD
+RLDRRRURULDLUDLDUDLLDUUURRDUDDURULLRRDDULUUDRRRULRUURRRLUUULRDRUDRRLLRLURDLDRDRDLLUDRUULRUDRUDDRURLRLURRDDRRURUUDRRDDRURURUDUUUDUDRRLRDRUUURLLUUUDLRUUDDRDDDDLDRLRDUDDULDDLRLLRURLLURLDDLDLDDULLDDUUURDLRUDUUDLDURDDRUULDRDDRDDDUUUDRDRDDRRDRRDLRDRURDUDDLUUUDULLUULULULRDRUUDDURURDRRRRLUDLDUDURLDRURDLLUUUDLRRDRRURDDULULURLDUDDLUDLDDLLRLDULLULULURUURLDULUDLLUUDLDDULDRRDDUULLUDLDLLRDRDURDDURDDURLDDURUURLLRURURUDDURRDRLRLDDUUDUULRDLLURRRRULURULDUDUDDUDDRLLLDLURDUURUURLUULRRLDLULDDRLDDUURULURUDRD
+URLDDRLLRRLDRLLRRURURURDDLRRRUUUURULRRUUDLUDRULLDLRUDDLULRUULDULURLLRLLUDDUDLURDRRRRLURULRURRURRULRRRULDLLDDLRLUDULUUUDDUDDRRDDDDUULRRLDRRULULRDUURRLDDRDULDURUDUDDLDLLURDDLDDRUDUUUDUUURDLDUDUUULLDLRDULRRRDLLURLDLLULRDDULULURLRLUULRLLLDDDUDLLDLURRRULRDUDDLULUDRUDDURULRLRUDDURLLURULLURDRULDUDLDULRRDLDURLUURRDDUDDUDRURUDDURRUUDURUULLLLDDRDDDDDULUUDDURRULLDRRLRRRRRDDRUUDDDURDRDRUDDUULDUDRRDRULUURLURLUDUDULDDRDULDLRUUDLLLRRLRDRDDUUULRDUDLUDLURRDUURDULDRLLDRDULDUDUULRLLDLRLDLUUDLRUULDUUULDLRLRLUULLLLRLRDUDRUUDURLDUDRRURLRUDRRLRDDLRDDLDDUDDDRLRLLRLUUURLURRRLULRLLDRLRDDRRDRL
+DLLLLLLRLRDRUDLRLLRLDLRURRUURLDLDDDDDUDUULLLLRRLRRDUUDUDLULLRRDULUDLLULURLRULURUULRLURDUDLUDULULUUURLRUDULURULRURULURLRLDRRRRLUDLLDULLDDLLULUURRULRDURDUUDDDURRUDLLLLRLDLUDDULLDUDDURURURRRRULDULULUDDUUDRLRLLLDLLLUUUURUDUUDLDLLRLRDDUULLUURLDDLRRDRLULDLULRULDLDURLULUURRRUDLLRDLUDDULRULULUDDURDLUUURDUUURDUDURLUUDRLUDRULUDDRRDLUUDLLLRDDDDDDLDURDDLDRDLUUDRULLUDRDLDULLULDDRUUDRRLRURRUULLRLRDUUURRDRRDULDDULUUDDURLULRLRURLLRRR
diff --git a/2016/02/puzzles.c b/2016/02/puzzles.c
new file mode 100644
index 0000000..81f6b5f
--- /dev/null
+++ b/2016/02/puzzles.c
@@ -0,0 +1,60 @@
+#include <err.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+int
+main(void)
+{
+ int x, y, ch;
+#ifdef PART1
+ int keypad[][5] = {
+ {0, 0, 0, 0, 0},
+ {0, 1, 2, 3, 0},
+ {0, 4, 5, 6, 0},
+ {0, 7, 8, 9, 0},
+ {0, 0, 0, 0, 0}
+#elif defined PART2
+ int keypad[][7] = {
+ {0, 0, 0, 0, 0, 0, 0},
+ {0, 0, 0, 1, 0, 0, 0},
+ {0, 0, 2, 3, 4, 0, 0},
+ {0, 5, 6, 7, 8, 9, 0},
+ {0, 0, 'A', 'B', 'C', 0, 0},
+ {0, 0, 0, 'D', 0, 0, 0},
+ {0, 0, 0, 0, 0, 0, 0},
+#endif
+ };
+ FILE *fp = fopen("input", "r");
+
+ if (fp == NULL)
+ err(EXIT_FAILURE, "fopen: 'input'");
+
+ x = y = 3;
+ while ((ch = fgetc(fp)) != EOF) {
+ switch (ch) {
+ case 'U':
+ if (keypad[y - 1][x] != 0)
+ y--;
+ break;
+ case 'D':
+ if (keypad[y + 1][x] != 0)
+ y++;
+ break;
+ case 'L':
+ if (keypad[y][x - 1] != 0)
+ x--;
+ break;
+ case 'R':
+ if (keypad[y][x + 1] != 0)
+ x++;
+ break;
+ case '\n':
+ putchar(keypad[y][x] <= 9
+ ? keypad[y][x] + '0'
+ : keypad[y][x]);
+ }
+ }
+
+ putchar('\n');
+ fclose(fp);
+}