From 3cc1430b049cd5cd713fcb2e8bfc2ca14ac1502f Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Fri, 2 Dec 2022 17:17:25 +0100 Subject: Add 2016 day 2 solutions --- 2016/02/.gitignore | 1 + 2016/02/Makefile | 1 + 2016/02/input | 5 +++++ 2016/02/puzzles.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 67 insertions(+) create mode 100644 2016/02/.gitignore create mode 100644 2016/02/Makefile create mode 100644 2016/02/input create mode 100644 2016/02/puzzles.c 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 +#include +#include + +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); +} -- cgit v1.2.3