#include #include #include #if 0 #define PART(line) part(line, 4) #else #define PART(line) part(line, 14) #endif #if 0 #define FILENAME "sample.txt" #else #define FILENAME "input.txt" #endif void part(char *line, int n) { n--; int times_seen['z'-'a'+1] = {0}; for(ulong i = n; i < strlen(line) - 1; i++) { int stop = 0; for(ulong j = i-n; j <= i && !stop; j++) if(++(times_seen[line[j]-'a']) > 1) stop = 1; memset(times_seen, 0, sizeof(times_seen)); if(stop) continue; printf("%ld\n", i + 1); return; } } void parse() { FILE *fp = fopen(FILENAME, "r"); if(!fp) { fprintf(stderr, "ERROR: Could not open file: %s\n", FILENAME); exit(1); } char line[4096]; while(fgets(line, sizeof(line), fp)) PART(line); fclose(fp); } int main(void) { parse(); return 0; }