summaryrefslogtreecommitdiff
path: root/2022/day06/main2.c
diff options
context:
space:
mode:
authorOrangerot <purple@orangerot.dev>2022-12-17 01:16:18 +0100
committerOrangerot <purple@orangerot.dev>2022-12-17 01:16:18 +0100
commit6596b48113ced669b206d2e1f1e8ba6edcba88a2 (patch)
tree02c7d01783390862d989df6c91aff968e03dd415 /2022/day06/main2.c
adv2022 first 8 days
Diffstat (limited to '2022/day06/main2.c')
-rw-r--r--2022/day06/main2.c26
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;
+ }
+ }
+}