#include #include #include #include int main() { //load input string FILE *file = fopen("input", "r"); if (file == NULL) { perror("main: error opening file."); return -1; } uint32_t ncount = 0; uint8_t two_repeating_check = 0; uint8_t two_separated_check = 0; char input[256]; while (fgets(input, sizeof(input), file) != NULL) { //two letters repeating test two_repeating_check = 0; for (uint8_t i = 0; i < strlen(input) - 1; i++) { for (uint8_t j = i + 2; j < strlen(input) - 1; j++) { if (input[i] == input[j] && input[i+1] == input[j+1]) two_repeating_check = 1; } } //two letters separated by one test two_separated_check = 0; for (uint8_t i = 0; i < strlen(input) - 1; i++) { if (input[i] == input[i+2]) two_separated_check = 1; } if (two_repeating_check && two_separated_check) ncount++; } if (ferror(file)) { perror("main: error reading file."); return -1; } printf("ncount: %i\n", ncount); return 0; }