From a985e96bf81241bcdc797ca376176e128ec4bcc5 Mon Sep 17 00:00:00 2001 From: kirreen Date: Wed, 11 Dec 2024 12:49:47 +0100 Subject: [PATCH] solved 11a --- 11/' | 92 ++++++++++++++++++++++++++++++++++++++++ 11/a.out | Bin 0 -> 19576 bytes 11/input | 1 + 11/inputDemo | 1 + 11/main.c | 116 +++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 210 insertions(+) create mode 100644 11/' create mode 100755 11/a.out create mode 100644 11/input create mode 100644 11/inputDemo create mode 100644 11/main.c diff --git a/11/' b/11/' new file mode 100644 index 0000000..0f9d26a --- /dev/null +++ b/11/' @@ -0,0 +1,92 @@ +#include +#include +#include +#include + +struct list { + int num; + struct list *next; +}; + +bool even_digits(int x) +{ + int i = 0; + while (x /= 10) + i++; + return i % 2; +} + +void split_stone(struct list *stones) { + int digits = 0; + int x = stones->num; + while (x /= 10) + digits++; + + int a = stones->num; + int b = 0; + for (int i = 0; i < digits; i++) { + b = b * 10 + a % 10; + a /= 10; + } + + struct list *tmp = stones->next; + stones->next = malloc(sizeof(struct list)); + stones->num = a; + stones->next->num = b; + stones->next->next = tmp; +} + +int main () +{ + // figure out data dimensions + FILE *input = fopen("./inputDemo", "r"); + unsigned int tmp; + unsigned int array[10]; + for (int i = 0; i < 10; i++) + array[i] = -1; + for (int i = 0; fscanf(input, "%d", &tmp) == 1; i++) { + array[i] = tmp; + } + fclose(input); + + // put stones into list + struct list *stones = malloc(sizeof(struct list)); + stones->num = array[0]; + stones->next = NULL; + struct list *current = stones; + for (int i = 1; array[i] != -1; i++) { + while (current->next != NULL) + current = current->next; + current->next = malloc(sizeof(struct list)); + current->next->next = NULL; + current->next->num = array[i]; + } + + // loop through list + for (int i = 0; i < 6; i++) { + current = stones; + while (current) { + // 0 => make 1 + if (current->num == 0) + current->num = 1; + // even number of digits => split, fix list shit + else if (even_digits(current->num)) + split_stone(current); + // (point first split onto second split, second split onto old ptr) + // else => mult 2024 + else + current->num *= 2024; + + current = current->next; + } + } + current = stones; + int sum = 0; + printf("Stones: "); + while (current) { + printf("%d ", current->num); + sum++; + current = current->next; + } + printf("%d\n", sum); +} diff --git a/11/a.out b/11/a.out new file mode 100755 index 0000000000000000000000000000000000000000..c18907fd0fc9f7998da8ec21a5710268e8ab1025 GIT binary patch literal 19576 zcmeHPdvILUc|UhoM_PF;tzNbz8=}S7U}AeE`Th1<@|r8-7uXJ_U@j}|O4@q0tL#IT z8H_z%4D1NE(m)cC@f4R~h$oc6Z8F7RNMt*MZ0fY4aa*NLrz(X+jv;}Drb-~Fzwg|0 zR#$5&P5TFb?U}jvJKy8?o$q}2+;bm$&mQq@+hWr+riz_yV8r#5m=dp4bT!Bdh?lKm zMcB_{x3YZjc|vCDy(WRyEJL=5)FI_|P{LJGWfFRmDQ1eQ2#FGIs?t+nY7}L%AB5wi zl6*G(SD|D~QKiqc=O!?UTkJDbCj%5ktvJff;9{X>gX<^K4w;uONfnM*!VOE@u*7Ak zY;Ranl~2kEZL4HHv#A$4DqgW?EF0G)aoKdUv{#hcptAe@MBx9^-Y$t-$v3SKYPdw^b zB0`|JYO&F-6DvOk1Y!>DW$!>1v0Pa>~_Y%=>@Q^+Z%$?Wf)LjDTm zZfx155`xM6kZdyf_aJv;%PyNBn42vm-Z0_`fAayOx$S__;tz#cOSB^xVeS5KINA&? z#z8Zg#1clkKNNu^6puEqUTw6*oBfd%@XcL*qa_saheHnsSxa*`8V|CLSSXTcVFacz zvx42Zt+BqrSmIfhsV(s=&(v3DYD` zzuWtDoQ5{`BzP)nUQ_eQ(Na@BBZu<%E{Yh& zmcI@0*!(NlyQ;mY5#L6-Yr|tG^Dhujw`|u21^+tnbgOo)U+{lLJl$GdJ0tjS6Hm8P z*G>ukdE)6->RJzYil^?w#`HT6>gjj&)O#Q8+T*M1ue+?DSpN+;9h>2V`6n$NSM_6n zAm9`04?&`z;4vbrM-wy9m0x(wt`v?9yQ+_p-9<@Z-ze;t*Auzpb3Of$e*PC5_4A{4 zU3*J^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CFNoo{?|J-=9N9IZ^&I z*A037P`^7!HzHP5CwdZ_74McfMLVpj$C2*;$VB1Q|4;PSkTqU&m?X1Tctw8$jTNu%vqvOe&mhf;!YOJ4*os&8 zr?s`Fy^2%0QMe2bFv(Q>UazU~N_@6GwPh_uvVCcuQ7Jsl@7AL5iq4dHs}0pVrNeB$ z3a9MnPl10?0?%cgf7$rDDe!(7_+SZFReEL^t@p$SuFb>8^t~= literal 0 HcmV?d00001 diff --git a/11/input b/11/input new file mode 100644 index 0000000..46fe4cc --- /dev/null +++ b/11/input @@ -0,0 +1 @@ +510613 358 84 40702 4373582 2 0 1584 diff --git a/11/inputDemo b/11/inputDemo new file mode 100644 index 0000000..9b26c84 --- /dev/null +++ b/11/inputDemo @@ -0,0 +1 @@ +125 17 diff --git a/11/main.c b/11/main.c new file mode 100644 index 0000000..dce1f15 --- /dev/null +++ b/11/main.c @@ -0,0 +1,116 @@ +#include +#include +#include +#include + +struct list { + unsigned long int num; + struct list *next; +}; + +bool even_digits(unsigned long int x) +{ + int i = 0; + while (x /= 10) + i++; + return i % 2; +} +// power! x to the y! +int pow(int x, int y) +{ + int ans = 1; + for (int i = 0; i < y; i++) ans *= x; + return ans; +} +void split_stone(struct list *stones) { + int digits = 1; + unsigned long int x = stones->num; + while (x /= 10) + digits++; + + unsigned long int a = stones->num; + int b = 0; + for (int i = 0; i < digits / 2; i++) { + b += (a % 10) * pow(10, i); + a /= 10; + } + + struct list *tmp = stones->next; + stones->next = malloc(sizeof(struct list)); + stones->num = a; + stones->next->num = b; + stones->next->next = tmp; +} + +int main () +{ + // figure out data dimensions + FILE *input = fopen("./input", "r"); + unsigned int tmp; + unsigned int array[10]; + for (int i = 0; i < 10; i++) + array[i] = -1; + for (int i = 0; fscanf(input, "%d", &tmp) == 1; i++) { + array[i] = tmp; + } + fclose(input); + + // put stones into list + struct list *stones = malloc(sizeof(struct list)); + stones->num = array[0]; + stones->next = NULL; + struct list *current = stones; + for (int i = 1; array[i] != -1; i++) { + while (current->next != NULL) + current = current->next; + current->next = malloc(sizeof(struct list)); + current->next->next = NULL; + current->next->num = array[i]; + } + + // loop through list + for (int i = 0; i < 75; i++) { + current = stones; + bool last = false; + while (current) { + if (current->next == NULL) + last = true; + // 0 => make 1 + if (current->num == 0) + current->num = 1; + // even number of digits => split, fix list shit + else if (even_digits(current->num)) { + split_stone(current); + current = current->next; + } + // (point first split onto second split, second split onto old ptr) + // else => mult 2024 + else + current->num *= 2024; + + current = current->next; + if (last) + break; + } + struct list *tmp = stones; + /* + int sum = 0; + printf("%d blinks: \n", i + 1); + while (tmp) { + printf("%lu ", tmp->num); + sum++; + tmp = tmp->next; + } + printf("\ntotal: %d\n", sum); + */ + } + current = stones; + unsigned long int sum = 0; + printf("Stones: "); + while (current) { + printf("%lu ", current->num); + sum++; + current = current->next; + } + printf("\ntotal: %d\n", sum); +}