From 13e902069b5bf7fda1311e740b5dd5cfa0b17fe0 Mon Sep 17 00:00:00 2001 From: kirreen Date: Sun, 8 Dec 2024 19:02:07 +0100 Subject: [PATCH] solved 6, with graphics lol --- 6/a.out | Bin 0 -> 19224 bytes 6/input | 130 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 6/inputDemo | 10 ++++ 6/main.c | 84 +++++++++++++++++++++++++++++++++ 4 files changed, 224 insertions(+) create mode 100755 6/a.out create mode 100644 6/input create mode 100644 6/inputDemo create mode 100644 6/main.c diff --git a/6/a.out b/6/a.out new file mode 100755 index 0000000000000000000000000000000000000000..f0395a568fd9bf116a3024adc6a3aebbc297449b GIT binary patch literal 19224 zcmeHPdvKf8mA{|lE6b5>*-o6;7_jo9fnwQCoREi;C~*|zJRqS->y*bAS(0rfvSjoy zPD^VK<`J(6lN4yvZrTl9ri6uE+}#XKVM-mKm@t`LGt07Rcef4Q!q}72(k>11Ua7)hgL67eWS)n>(jc-U%I zf_w>E%xsVg1Sa(!NuZVKf@M0jE8Gf7epSTGK(CZA(^R*RDEZBns#FD6$!GN!54XX8T!5wHO=;;*o@angYos#>0uR@ql#)j63OqP^1G<~GL#xb zdPQ|SDJJw=t>T$WJZf?M9jTh zG=bXHfFDhp8*kdnECXzmFzs(JW14JHGE77w+j;m=*vbFf8!p|s|IpVSc&FmruI`0T z{QJQC?|p}Cs2@}&*-#>kemap(|1|c;&{`N(%wV`~7W`4*t{Loao5j9#7CbNuUN{R* zeVeJB-v#c%FE=#-n92TAv*4q^UHIjuod6c)f{^L3oT+@)(HTkxSUhxBI2vT8nMnEr z2hBj&L9@djj^~A%`WCtT-nun{{jXPR5x0uV_O&M;*6uaELl9{c0cACLZJk%LZ zBt!8%J6j^LXlReWJrY74o!zmhs@0UHGa52x!7Me97vM*K#82f`b^tNa$J@McxP)eC zQemf$eHDkTm3>*ssVl-oRN@e1N_t(?>(NNL#4o6IPviR)zRM%^8rSmZMv2oJp$=&Q zyqblpB~IYuSvVS$Nf)y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DE*Z(nK6cb&3<~*a$ zH#EPqQ||bmfHK?PrTjEKne7Z-pT;zOBFBGJDKxE6&(n1=+E2@WpX0BuYcwsAPvf9=1=C9O4GBE?Le>wgZKZ2vx&G}ZL(jHhJu_-XiG z!Qi2aI0gvQ?=$rO0m-%3vZgijfvW>I&e_wUHK_6JMxR3R9yYkQN=j3YX zK#$n7ldfM=x~?Za*MIvu=|$^ncG7;?G^Yw-KB4^e#8?EBjuSl}^!cj@n4UYrQDqYw aBr~QfQh1Jtd!d>ApYceCjvR*^k^Mj2$?kyw literal 0 HcmV?d00001 diff --git a/6/input b/6/input new file mode 100644 index 0000000..de833c2 --- /dev/null +++ b/6/input @@ -0,0 +1,130 @@ +.#....#...................#................#......................#.#...............#................#....#...........#..........# +.................................#.....#............#............#.......#...#...##........#..............................#....... +..............#.#............#...............................................##.................#....................#..#......... +..............#.............................#...........................#....#....#........#.................................#..#. +............#.#..#.#...........................#.....................................#..........#............#.................... +.#......................................................................#..................................#......#............#.# +...........#.............................#....................#...#.....#........#....##.........................................# +......#..##.......................................................................#............#.................................. +........#.......#..........#.......#........#..................#....................#.............#.....................#......... +................#....#.##.........................#........#....#.................#............................................... +.............#........................................#....................#...............#.....#.............#...............#.. +..........#.........................#...#.......................#.............................................#......#............ +........#................................................#..........#.............#.............#.........#....................#.. +....#............#................#.....#.#................#..................#.................#................................. +....#.........................#.............#.....#..................#....#............#...................................#...... +...##....................#.............#...............................................#.......................................... +.....##.......................#...................#................#..........#.....................#...................#......... +....#....#..................................................#.......................................................#............. +...#........##.........................#.......................#........#...................#...........#...................#..... +.....................##.#...................................................................#.............#....................... +........#..............#...................................................#.....................#...#.......#..#.............#... +..................................................#.......#...............#.............#........#..#.....................#....... +..#..................#...............##..................#.#.........#..........#..............#....................#..#.......... +...#..................................................#...........................................#........#...................... +#.................................................#..............#...#..........#....................#....................#......# +..#...#....#...........#.................................#......................................#.......................#.....#... +...#...........#..#................................#......#.............#........................##.................#....#....#... +....................#.........#.......................................................................................#........... +............................................................#................#.#..#.....#.....................#................... +.......................................#......#....................................#........................................#..... +...........#.............#...............................#..........#.........#...#.......................................#....... +.............#...............................#.#...................................................#.....#............#........... +.......................................#...#....................#.#..........##.................#...............#............#.... +....................#..#....#.............#..............#....#.........................................#.##.....#................ +......##..............................................................................................#........................... +....#.......#.............................#..#.........#................................#.........#............................... +..........................................................................#...............................#...........#.#......... +...............#..................................................#.........#.....................#...............#............... +.........#......#............#.........#................................#..............................##......................... +...............#.....................................#............................................#........................#...... +..#...........#...........................................#.........................................................#............. +................................#......##..#............................................................................#......... +.........#...........................................#....#..............#......................##....#..#........................ +.....#.............#.....#........##......................#...#..................................................#.........#..#.#. +...........................#.........#.......#..........................##...........................#..............#............. +...............................................................................#..#........................#................#.#... +.....#.#.............................................................#.........#...........#..................................#... +.....#....#..#........#....................................#...................................................................... +#......................................#..#..............................#..#................#........#........................... +.....................................................................................................#.......#....#.........#..... +....#....#............................................#................................................................#.......... +......#.................#.......#..............................................#...................#.............................. +...................#.........................................................................................#.................... +.............................#................#.#......#...#.......................................#............#............#.... +...........................................................#..........#..#.................##.....#..#............................ +.....#......................................................#..............................#........................#............. +...............................................#.............#........#.......................................#.......#........... +.............................................................#.............................#...........#.#...................#.... +.......#......#......#......................#..................................#^.......................#.........#.......#....... +...........................................................................................................#....................#. +.....#............#.....................#....................#.................................................................... +....#...........#................#.....##.............................................................#....................#...... +.................................#.#....................#......................#......................#.#.................#....... +..................#......#...#..........#............#................#...#.................................................#..... +...............................................................................................................#...#.........#.... +...............#.........#..............................#.......#.......#.......#................................................. +.#........#...#......................................#........#...#.......................................................#..#.... +.....#...............................................................#.....#..........#.........#.....................#........... +.........................................................................................................#...#.........#......#... +.....##..................#...#.....#.........#......................................#...............................#............. +..#...............................................................................................#............................... +........#..............................#.#........#.#..#...................................................#.#.................... +........................................................#........................#..#............................................. +.....................#.......................#..................................#..........................#....#................. +.........................##.........#.................................#................................#....#..................... +..#........#.......................................................................#.....#........................................ +.....#.....................................#.....#....................#...............#........................................... +......................#....................................................................................................#...... +...#.........................#......................................................#.......#.......#..#.....................#.... +............#...#....................................................#....#......#...............#.......#......................## +.......#.................................................#...#.....................#..................#........................... +.#...................#.....#.#..............................................................................#..................... +..........#...............#......#...........#......................................................#.....#.............#...#....# +.......##.........#.....................................................#....#.........................................#.........# +..##..................#............#..#........................................#..................#..##........................... +..................#....##..............................#.....#...............#.................................................#.. +........#..........#...................#.............#...............#..#........#................................................ +........#..............................................##....#.................................................................... +.........#.#............#.........................#..............#................................#......................#........ +........#.#............................#.....#....................................................................#............... +.......................................#......................#...........................#....................................... +..........................##.....................##..#............................................................................ +#.............#..............................................................................#...........#........................ +......#....#.....................................#........................#....................................................... +#...................#.#.......#.......#.....................#.....#...........................................#................... +...#.......................................#............................................#................#........................ +...........#.............................#........................................................................................ +...............................................................#.............#..................................................#. +.........#........#....#.#..............................................#......................................................... +.........#....#....#...................#..........#............................................#..##.............................. +....#...#.......................#..#....................#...#..........................##..#....#.........................#....... +....#.....##...........................#.#..............#.......................#...#.......................................#..... +......................................................................................#.#..#.....#............##....#....#........ +..............#..................................................................##....#.............#............................ +................##...#..............#........................#.......................#.#...#......................#............... +...#............................#...#......#.#............#........#......................#........#................#............. +..........#.....................................#.....#...............................................................#.........## +.........#.......#...................#.#.........................................................#................................ +...........................#.#............................#...................#.................#.........#....................... +.....#....#.........#................................................................................#...#..................#..... +...............................#....#............................#............................................#.............#..... +......#...............#......#.........................#.#........................................................................ +.......................................................................................#...................#.........#.#..#....... +.....#...................................#..................................................................#........#............ +...........................................#.......................................#....................#............#...#........ +....#............................#..................................#.#....#......................#....#..#.......#...#........... +.#....#................................................#..................#.......##..........................#...#............... +........#...................##...........................................................#...................................#.#.. +...#..........#.#....#...................#......#................................................................#................ +....#............................#....#......#..#............#..................#........#..........#....#....#........#.#........ +................#....#...............#...#.#..............................................#............#................#......... +.......#.....#.#.................#......................................................................#..#...................... +.#......................#.................................................#......#..........#......#....................#......... +......#.#............................#............#.......#............#.....#.................................................... +.#.............#.........#..................................................#...#...........#..........#............#..#.......... +...........#......#...........#............................#.......#......#......#..........#....##..#............#............... +..........................#........#.........................................................#......#........................##... +.................#....#............#...#...........................#....#....#....#...#........................................... +.............#.......................................................#.........#.................................................. +....#.................................#...............#.....#....#......##..............#.......................#........#........ diff --git a/6/inputDemo b/6/inputDemo new file mode 100644 index 0000000..a4eb402 --- /dev/null +++ b/6/inputDemo @@ -0,0 +1,10 @@ +....#..... +.........# +.......... +..#....... +.......#.. +.......... +.#..^..... +........#. +#......... +......#... diff --git a/6/main.c b/6/main.c new file mode 100644 index 0000000..db52c22 --- /dev/null +++ b/6/main.c @@ -0,0 +1,84 @@ +#include +#include +#include +#include +#include + +int main () +{ + int guard[2]; + int rot = 0; + int dir[4][2] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; + + // figure out data dimensions + FILE *input = fopen("./input", "r"); + int width = 0; + int height = 1; + while (fgetc(input) != '\n') width++; + for (char c = fgetc(input); c != EOF; c = fgetc(input)) { + if (c == '\n') + height++; + } + rewind(input); + printf("Dimensions: %d x %d\n", width, height); + + // make 2d array + char **grid = malloc(width * sizeof(char*)); + grid[0] = malloc(width * height); + for (int i = 1; i < width; i++) { + grid[i] = grid[0] + i * height; + } + + // put the data in the array + for (int i = 0; i < width; i++) { + for (int j = 0; j < height; j++) { + grid[j][i] = fgetc(input); + if (grid[j][i] == '^') { + guard[0] = j; + guard[1] = i; + printf("guard coords: %d/%d\n", guard[0], guard[1]); + } + } + // skip newline + fgetc(input); + } + fclose(input); + + // sum it + int sum_x = 0; + // step (mark current X, check forward, step or rotate) until oob + while (true) { + // graphics! + /* + printf("\e[1;1H\e[2J"); + for (int i = 0; i < width; i++) { + for (int j = 0; j < height; j++) { + printf("%c", grid[j][i]); + } + printf("\n"); + } + usleep(2000); + printf("\e[1;1H\e[2J"); + */ + + if (grid[guard[0]][guard[1]] != 'X') { + sum_x++; + grid[guard[0]][guard[1]] = 'X'; + } + // oob? + if (guard[0] + dir[rot][0] < 0 || + guard[0] + dir[rot][0] >= height || + guard[1] + dir[rot][1] < 0 || + guard[1] + dir[rot][1] >= height) + break; + if (grid[guard[0] + dir[rot][0]][guard[1] + dir[rot][1]] == '#') + rot = (rot + 1) % 4; + // step + guard[0] += dir[rot][0]; + guard[1] += dir[rot][1]; + } + + + + printf("total Xs: %d\n", sum_x); +}