From 697f949debc110c2a498d8c5b470b7790dc53e02 Mon Sep 17 00:00:00 2001 From: kirreen Date: Sat, 7 Dec 2024 22:09:46 +0100 Subject: [PATCH] finished 4a --- 2/a.out | Bin 15688 -> 15888 bytes 3/a.out | Bin 0 -> 19704 bytes 3/main.c | 18 ++----- 3/mainB.c | 92 ++++++++++++++++++++++++++++++++++ 4/' | 41 +++++++++++++++ 4/a.out | Bin 0 -> 19472 bytes 4/input | 140 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 4/inputDemo | 10 ++++ 4/main.c | 75 ++++++++++++++++++++++++++++ 9 files changed, 362 insertions(+), 14 deletions(-) create mode 100755 3/a.out create mode 100644 3/mainB.c create mode 100644 4/' create mode 100755 4/a.out create mode 100644 4/input create mode 100644 4/inputDemo create mode 100644 4/main.c diff --git a/2/a.out b/2/a.out index 2ec387cfb8e33414cfcd32f3ca06804323a12f5d..fa4e919c6e64ab9bf2ee8f4b18b50f1fe072bb2d 100755 GIT binary patch literal 15888 zcmeHOe{dAl9e;NLi4k&<292U}RdK)$M*;~A0(w9eHX4LNQgueUJ#rUvHMxtIiv%kr zodY}9BbHigZO1=oJJULyIx;Q8FiPnKoFq7ojh5+P|FF^OcoAA7MvZ`6Ki{|SyX>ur zb?lG7_GNaz@B8`wc<+7R+r78h@9xwZ)_6T0!KFytDu~-xW+Fi)*tD zq<^4+pfF{*)t+C9g>cZjNdbka-Hu!iEs$a{w4#u9tGM(i%67z(-LSG7R(2Lu?F}o+ z@uZm0QLEzVq(R821m#%>r(L(QbJ9Ac&y?Drvgxg4_=~i+LD`l2r5oX-+zwN2?`yDA zQ)C+cn=?=IM%CVA^H8bc&s2p~ENqKzSyH{QExe#D8tdv_&|SM^!IJ7gXFRY-woLu1 z#6fFn?VU}++at1svAsul3V5%BC*5)!6n3(Iq;}@(>(4$n<-R5Hzn|$l`{L|JYQ{;2 z#z8(whYDeIa3L8VjC~$j0i~G}DBe5?z6-d20)4vNCi1g!5}f)vk^UW%;QN64aX8Bj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ove<)c#}sz&WaLg IC2Ed;0Wg{d&j0`b diff --git a/3/a.out b/3/a.out new file mode 100755 index 0000000000000000000000000000000000000000..d9e3c16836edae6ce3081e2ff966efa5f8672145 GIT binary patch literal 19704 zcmeHPe{@t;e!p*K-ekg%OhWjP04^hf3nG&QVgMyF0R~?bg+)-%)tAZ4OEP6LlgW*D*JE7srG=CFy6R(ch)M&C;&k&)qOP zT`gdysH*QPu%ozq(WHiXi>z<5acGk9S5$_THO6CItu2l5=+byBk=?y?_sZ6#tu29c zGO&y{f!fuCgQm@GcWq;i{VYeAve%ea!aF1n6`n|UIt~gu*$;j@n|pcn+#Q=%KKH@g zmu`OXqt!Fck`DEQe3A|&!st+mWa?1Z7op3cG;IRKXMy=Az#D)~q<`NeIL)t#^uv?j z)Q5@mw@!lp6>vWed%6+8M1FcF!RJkazXRNl!=6F_=G#H=3voY(_PWD>~md>Q`$NIwYcrpT2%)JQdr!r<=IF@NS7^XU8h(EI1(fA0B=Nr@4bY1)h?+ZmR25u2$d|&=Lx`3h(6ifw(yu@1d5<-8n$asMs2ORBM9&YvcpmQrIm&i^IxwDcJ}!TFborzOwW zQO>_WJS}y`4srfZiKivb*nZAGO*}0##`-z`1o5<_8SCWy0pe+iHntf&^{4q?I|ko- z&=~xsG4R2q&09mwx#si6!M3N+sQiq-2{3lKJK&r5b(o;T2itbQfpJjZLS)sI%nXF$ zRVYy?D)S@0dHYH4jHJ+C%=K@YPh|0D#^5F6t$$l%ymiHCXlIT0KFdspgT2y$CqL5d zo40=4p4zv+?L&xJcKJ4ApzS^?8iOBZs*ItwvtaTw4CJE`bmpx728!APXU5xmrhB|h z<3aw$dZ4=vJ}{6q#^By7#$fi+#i_`4Qsi>-W(gY>XE-7-HUL2^$WSa z`oD3FNc+AYx+?oM@KI;f7;-IKgg((wHRsNSj#B?HC%drZHU`h4bRRFB8@+m!MlEy- z@jP{!&ayYT>fpK2pOOTqf$~cz4~C8ng^n2mIgOBG!Y-#YGT?`@$BdzEZ2L$$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ht@RzTy@AC)m)tb$Qw`^?TNZrQ~gVz6frdSN0bnpt+;$ z)q1}0e|xBNNOD>h=ARlz+Q>#K%3l3{id-XEF}6sMLaypn^w*FS+pFh;QEA^>uoMMl zr>FzQ#rA4ly}3!~t9B|k%C5k}m@w7;&Y+NVN_)FL)m5CTWc^aTAX4^peJ@VRUeTG- zzF3FK&q#-MzsgSOFPy~wtTZ&`^;GHG?VBgDUnm<+Ka>i$LVAl2Lv79xK|>3Mk~`zO~5jc%KPjb;B0&IUYN literal 0 HcmV?d00001 diff --git a/3/main.c b/3/main.c index b051d8e..4cb367f 100644 --- a/3/main.c +++ b/3/main.c @@ -12,7 +12,7 @@ struct instruction { void addInstruction(struct instruction *start, char *coord) { - // traverse list until null next + // traverse list until last member while(start->next) start = start->next; // allocate and store ptr @@ -24,8 +24,6 @@ void addInstruction(struct instruction *start, char *coord) } bool confirm_numbers(char *start, char *end) { - if (start >= end) - return 0; for (int i = 0; (start[i] >= '0' && start[i] <= '9') || start[i] == ','; i++) { if (start[i + 1 ] == ')') return 1; @@ -51,31 +49,24 @@ int parse_numbers(char *string) return a * b; } -int find_coord(char *instructions, int start) -{ - return 1; -} - - int main() { unsigned int sum = 0; char instructions[32]; - int a = 0; - int b = 0; FILE *input; input = fopen("./input", "r"); fseek(input, 0L, SEEK_END); unsigned int fLen = ftell(input); - char *memory = malloc(fLen * sizeof(char)); + char *memory = malloc(fLen * sizeof(char) + 1); rewind(input); fread(memory, fLen, sizeof(char), input); + memory[fLen + 1] = '\0'; fclose(input); - // find first instruction for the list head + // find first instruction start for the list head char *start = memory; start = strstr(start, "mul(") + 4; struct instruction *list = malloc(sizeof(struct instruction)); @@ -97,6 +88,5 @@ int main() current = current->next; } - printf("%d, %d\n", a, b); printf("%d\n", sum); } diff --git a/3/mainB.c b/3/mainB.c new file mode 100644 index 0000000..4cb367f --- /dev/null +++ b/3/mainB.c @@ -0,0 +1,92 @@ +#include +#include +#include +#include + +#define LINES 1000 + +struct instruction { + char *coord; + struct instruction *next; +}; + +void addInstruction(struct instruction *start, char *coord) +{ + // traverse list until last member + while(start->next) start = start->next; + + // allocate and store ptr + start->next = malloc(sizeof(struct instruction)); + + // store coords in new item + start->next->coord = coord; + start->next->next = 0; +} + +bool confirm_numbers(char *start, char *end) { + for (int i = 0; (start[i] >= '0' && start[i] <= '9') || start[i] == ','; i++) { + if (start[i + 1 ] == ')') + return 1; + } + return 0; +} + +int parse_numbers(char *string) +{ + int i = 0; + int a = 0; + int b = 0; + while (string[i] >= '0' && string[i] <= '9') { + a = a * 10 + string[i] - '0'; + i++; + } + // skip comma! + i++; + while (string[i] >= '0' && string[i] <= '9') { + b = b * 10 + string[i] - '0'; + i++; + } + return a * b; +} + +int main() +{ + unsigned int sum = 0; + char instructions[32]; + + FILE *input; + input = fopen("./input", "r"); + + fseek(input, 0L, SEEK_END); + unsigned int fLen = ftell(input); + char *memory = malloc(fLen * sizeof(char) + 1); + + rewind(input); + fread(memory, fLen, sizeof(char), input); + memory[fLen + 1] = '\0'; + fclose(input); + + // find first instruction start for the list head + char *start = memory; + start = strstr(start, "mul(") + 4; + struct instruction *list = malloc(sizeof(struct instruction)); + list->coord = start; + list->next = 0; + + // find the rest of the instructions and append to the linked list + while (start = strstr(start, "mul(")) { + start = start + 4; + // confirm format %d,%d) + if (confirm_numbers(start, memory + fLen)) + addInstruction(list, start); + } + + // from each instruction start, parse and mult numbers + struct instruction *current = list; + while (current) { + sum += parse_numbers(current->coord); + current = current->next; + } + + printf("%d\n", sum); +} diff --git a/4/' b/4/' new file mode 100644 index 0000000..91ebd95 --- /dev/null +++ b/4/' @@ -0,0 +1,41 @@ +#include +#include +#include +#include + +int xmas_detector(char *x) +{ + int directions[8][2] = {{-1, -1}, {0, -1}, {1, -1}, {1, 0}, + {1, 1}, {0, 1}, {-1, 1}, {-1, 0}}; + for (int i = 0; i < 8; i++) { + for (int j = 0; j < 3; j++) { + + } + } +} + +int main () +{ + // make 2d array + FILE *input = fopen("./inputDemo", "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++; + } + printf("%d\n%d\n", width, height); + + char **grid = malloc(width); + grid[0] = malloc(width * height); + for (int i = 1; i < width; i++) { + grid[i] = grid[0] + i * height; + } + + grid[0][2] = '5'; + + // find x + // + // confirm mas in all 8 directions +} diff --git a/4/a.out b/4/a.out new file mode 100755 index 0000000000000000000000000000000000000000..6b652fa8c2c242128fb96d5911c52cd16e83cbd9 GIT binary patch literal 19472 zcmeHP4RBl4mA+5%ljX>^>^Kf~5{MEKpn=FvNP?3%jhy5K8Ill4LXz^M$kLOo#Fkv? z$v6yP7l$-n0b{oecz3f9I_x&vrUTt&GZeauLjVKIY~60AlbvN|-41l@Chdl$Yy)M{ ze&_zkvamayc4lXGM%SZz&iT$c_nv$1`+x7c$Jn;jrfEzSJNq&t>4ge`_@rWVlVm`A ztbvuGUdom*2jn7-3B6AcXhk`1n@XJ$w}X;j4KdTu1p;P@stAda-%Mq!SZEYwavbER zlS<0@^sl*+F-4U=+nAW0IWMX3)eyFReOe@uTnm7j+xF2A8j@_@7Tj^y=<5;<*zYqifofIOn4#NIrvf9$$$Qw>qtus?(@gwgD23|Gv6r-6H>vA<&m`|=s^{WIXS z+fEk`jcq#o+rT~e<(Fjurn6r%1AZE~2fzHX8NlLvkmN|KX@ywAye}FHvp^te1w)4d zp|(STNHE&YA_>!Ek$9&WV;#Zv_IL;;*pfnIm#_jI!DtLfs5=;lL}S7B=>4z`wa1et z>r6yrR)mo;ZDniN&D)wcZ4RvTuF7&ZPO>Y#t689V_x3>8Oqi|Fq-7>{Z{OS=kD0rJ zE$t@yXzhr{WUm2XI;|mNHf)0$>LUE;k9bkja5ZQTfU5mzPBdCZTi`*7y*T(Jc1t_6 zq@0=;Eul7hAX8DtJ$1Y}Q7Q2A^0=n(of7x^gkIrF9^NQ$ItIvHmIH6);PMd0@zER{ z0cFei9K1A(;&_{bV}O&zCs^7(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=1 z#sYM>l;_JS4U6+wpe31<&GBO+U#UCQE`W8k0b|FO!0%f%J9P=~)CQ0l3-?aR!yPzj zfLaMb+Z2cMi<#(T-dNl+y{)m7w=;nS!wKtf4%Cv0V(B@~VZy3uQ}c2w*vhzhTQJ$i zyy3$!bRj4%5xAxcr!;)LF+~VKmoVFd~C9`XcYvjpDQM#|s zEo7Tpu7*I@>^2EDNPk6r5?4f=`jmu+Ltu0LyQROPbbiV$>iDRzW-z(_$EClb9%U$L zzW-j}|BYvsD*j>Vuc#WoL;B~(9|Vq@uk858q`#tcyrx1i607{_PK!zuKXOt1tLMgw zj*?MM$Ig;AVJ_h=9Taz$U&!CHz$hoG{p@)~o?q1Se3du zPCH+Y1#qBjUJTj%?~4Nb0pn@5-`O8Lz#YW@}WuVC<;hVKJ}srNAI|Ci+3 zD_PP1fDb)nmb)EO?`h62r`9I77a>i`%KriswCyN=b={o(e>5~W6uDVuw?8$Hzk!ZS zl)w7F4a0Thh41_X$=0f0ML&Ti*I&Ko8JGV1vYvubeu~=Qoa^uN2|HiCpejxwO^!b+ z!%tNfJx(i!|u zOUDIxc9>i8{a4K3{}Z|6JeB8=C$fz*_(yLNy?WG+C4&oga^4WR`H=Ki8`jl8X+KljlRE#E j08`r@ca+u8M!~$A*I}NBd#CCB_cjTCdfAm*@ +#include +#include +#include + +int xmas_detector(char **grid, int x, int y, int width) +{ + int real_xmas = 0; + char MAS[3] = {'M', 'A', 'S'}; + int dir[8][2] = + {{-1, -1}, {0, -1}, {1, -1}, {1, 0}, + {1, 1}, {0, 1}, {-1, 1}, {-1, 0}}; + for (int i = 0; i < 8; i++) { + if (x + dir[i][0] * 3 < 0 || + y + dir[i][1] * 3 < 0 || + x + dir[i][0] * 3 >= width || + y + dir[i][1] * 3 >= width) + continue; + for (int j = 1; j <= 3; j++) { + // holy can you read that coordinate? + if (grid[x + dir[i][0] * j][y + dir[i][1] * j] != MAS[j - 1]) + break; + else if (j == 3) + real_xmas++; + } + } + + return real_xmas; +} + +int main () +{ + // 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[i][j] = fgetc(input); + } + // skip newline + fgetc(input); + } + fclose(input); + + // find x + int sum_xmas = 0; + for (int i = 0; i < width; i++) { + for (int j = 0; j < height; j++) { + if (grid[i][j] == 'X') + // confirm mas in all 8 dir + sum_xmas += xmas_detector(grid, i, j, width); + } + } + + printf("total xmases: %d\n", sum_xmas); + free(grid[0]); + free(grid); +}