summaryrefslogtreecommitdiff
path: root/2022/day06/main.c
blob: 5b96fb9d53373fa9aa488bfcd911f74cd37fa44f (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 <stdlib.h>
#include <stdio.h>

int main()
{
    char *line = 0;
    size_t len;
    ssize_t nlen = getline(&line, &len, stdin);
    int distinctChars = 4;
    for (int i = distinctChars -1; i < nlen; i++)
    {
        int isTwoEqual = 0;
        for (int ii = 0; ii < distinctChars; ii++)
        {
            for (int iii = 0; iii < distinctChars; iii++)
            {
                if (ii == iii) continue;
                isTwoEqual |= (line[i-ii] == line[i-iii]); 
            }
        }
        if ( !isTwoEqual ) {
            printf("%d\n", i+1);
            return 0;
        }
    }
}