diff options
Diffstat (limited to '2022/day06/main.c')
-rw-r--r-- | 2022/day06/main.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/2022/day06/main.c b/2022/day06/main.c new file mode 100644 index 0000000..5b96fb9 --- /dev/null +++ b/2022/day06/main.c @@ -0,0 +1,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; + } + } +} |