diff options
author | Thomas Voss <mail@thomasvoss.com> | 2022-12-02 17:17:25 +0100 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2022-12-02 17:17:25 +0100 |
commit | 3cc1430b049cd5cd713fcb2e8bfc2ca14ac1502f (patch) | |
tree | 9c95e3e87781be0e7041dbada4df8b7151b731e4 /2016/02 | |
parent | 093de3f52b0b7dfb7cc42e05c9c4267c7011c001 (diff) |
Add 2016 day 2 solutions
Diffstat (limited to '2016/02')
-rw-r--r-- | 2016/02/.gitignore | 1 | ||||
-rw-r--r-- | 2016/02/Makefile | 1 | ||||
-rw-r--r-- | 2016/02/input | 5 | ||||
-rw-r--r-- | 2016/02/puzzles.c | 60 |
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); +} |