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