aboutsummaryrefslogtreecommitdiff
path: root/advent-of-code/2022/06/2.c
blob: 4cf030cd8754c79f99dface397aa25af20db245a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <stdio.h>
#include <stdbool.h>

bool succ(char *buf) {
    bool table[26] = {0};
    for (int i = 0; i < 14; i++) {
        if(!table[buf[i] - 'a']) table[buf[i] - 'a'] = true;
        else return false;
    }
    return true;
}

int main() {
    FILE *fp = fopen("input", "r");
    char buf[14] = {0};
    int i = 0;
    int c;
    while ((c = fgetc(fp)) != EOF) {
        if (c < 'a' || c > 'z') continue;
        buf[i % 14] = c;
        if (i >= 14 && succ(buf)) break;
        i++;
    }
    printf("%d\n", i+1);
    return 0;
}