Advent of code 2025 (not proud)
1#include <stddef.h>
2#include <stdio.h>
3#include <stdlib.h>
4int main(int argc, char* argv[]) {
5 FILE* f = NULL;
6 size_t size = 0;
7 char* line = NULL;
8 ssize_t nread = 0;
9
10 unsigned long long bat_sum = 0;
11
12 f = fopen(argv[1], "r");
13
14 while ((nread = getline(&line, &size, f)) != -1) {
15 unsigned long long bat_n = 0;
16 int number_of_batteris = 12;
17 int b_i = 0;
18 int a_i_1 = 0;
19 int a_i = -1;
20 int b = 0;
21 printf("line: %s",line);
22 // go through each line (we can keep as chars) get the largest number, get its index,
23 // go through second loop starting from that index, get the largest number there.
24 // i love loops within loops
25
26
27 //generalizing for n amount of battteris
28
29 for (int n = number_of_batteris; n>0; n--) {
30 a_i_1 = a_i;
31 a_i = 0;
32 int a = 0;
33 for (int i = a_i_1+1; i< nread-1-n+1; i++) { // we dont need line end char i think., and we cant choose the last one since then there will be no place for the second battery
34 if (a < line[i] - '0') {
35 a_i = i;
36 a = line[i] - '0';
37 }
38 }
39 bat_n = bat_n*10;
40 bat_n += a;
41 }
42
43
44
45
46
47
48 printf("digits :(%llu)\n\n",bat_n);
49
50 bat_sum += bat_n;
51 }
52
53
54 printf("bat summ: %llu\n",bat_sum);
55
56
57 free(f);
58 free(line);
59 return 0;
60}