Advent of code 2025 (not proud)
1#include <math.h> 2#include <stdio.h> 3#include <stdlib.h> 4#include <string.h> 5 6 7int count_digit(unsigned long long num){ 8 int len = 0; 9 while (num!=0) { 10 num /= 10; 11 len++; 12 13 } 14 return len; 15} 16 17int part_one_invalid(unsigned long long num) { 18 int answer = 0; 19 20 int len = count_digit(num); 21 if (len%2) { 22 answer = 0; 23 } 24 25 //it gonna be pair so no worry 26 unsigned long long halfer = pow(10, len/2); 27 28 if (num/halfer == num%halfer) { 29 answer = 1; 30 } 31 return answer; 32 33} 34 35 36int part_two_invalid(unsigned long long num) { 37 int answer = 0; 38 int len = count_digit(num); 39 int j; 40 41 for (int i =1; i<=len/2; i++) { 42 if (!((len%i)==0)) { 43 continue; 44 } 45 int chunk_num = len/i; 46 // use / and % to isolate chunks, with powers of 10 to the i 47 long long first = num % (long long)pow(10, i); 48 49 for (j = 1; j< chunk_num; j++) { 50 long long chunk = num % (long long)pow(10,i*(j+1))/ (long long)pow(10,i*j); 51 if (chunk != first) { 52 break; 53 54 } 55 } 56 if (j == chunk_num) { 57 answer=1; 58 } 59 60 61 } 62 63 64 65 return answer; 66} 67 68int main (int argc, char* argv[]) { 69 70 FILE* f = NULL; 71 char* line = NULL; 72 73 unsigned long long start = 0; 74 unsigned long long end = 0; 75 long long front_part = 0; 76 long long end_part = 0; 77 unsigned long long invalid_sum = 0; 78 ssize_t nlength; 79 size_t size = 0; 80 81 f = fopen(argv[1],"r"); 82 83 while ((nlength = getdelim(&line, &size, ',', f) != -1)) { 84 start = atoll(strsep(&line, "-")); 85 end = atoll(strsep(&line, "-")); 86 87 printf("start: %llu ",start); 88 printf("end: %llu\n",end); 89 90 91 92 93 for (unsigned long long i = start; i<=end; i++) { 94 95 96 97 if (part_two_invalid(i)) { 98 invalid_sum += i; 99 printf("invalid number found: %llu\n",i); 100 101 } 102 103 104 105 106 107 } 108 109 110 111 } 112 113 114 printf("invalid sum: %llu", invalid_sum); 115 116 117 free(line); 118 free(f); 119 return 0; 120}