···11+#include <stddef.h>
22+#include <stdio.h>
33+#include <stdlib.h>
44+int main(int argc, char* argv[]) {
55+ FILE* f = NULL;
66+ size_t size = 0;
77+ char* line = NULL;
88+ ssize_t nread = 0;
99+1010+ unsigned long long bat_sum = 0;
1111+1212+ f = fopen(argv[1], "r");
1313+1414+ while ((nread = getline(&line, &size, f)) != -1) {
1515+ unsigned long long bat_n = 0;
1616+ int number_of_batteris = 12;
1717+ int b_i = 0;
1818+ int a_i_1 = 0;
1919+ int a_i = -1;
2020+ int b = 0;
2121+ printf("line: %s",line);
2222+ // go through each line (we can keep as chars) get the largest number, get its index,
2323+ // go through second loop starting from that index, get the largest number there.
2424+ // i love loops within loops
2525+2626+2727+ //generalizing for n amount of battteris
2828+2929+ for (int n = number_of_batteris; n>0; n--) {
3030+ a_i_1 = a_i;
3131+ a_i = 0;
3232+ int a = 0;
3333+ 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
3434+ if (a < line[i] - '0') {
3535+ a_i = i;
3636+ a = line[i] - '0';
3737+ }
3838+ }
3939+ bat_n = bat_n*10;
4040+ bat_n += a;
4141+ }
4242+4343+4444+4545+4646+4747+4848+ printf("digits :(%llu)\n\n",bat_n);
4949+5050+ bat_sum += bat_n;
5151+ }
5252+5353+5454+ printf("bat summ: %llu\n",bat_sum);
5555+5656+5757+ free(f);
5858+ free(line);
5959+ return 0;
6060+}