summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Spragg <adam@spra.gg>2022-12-06 14:38:16 +0000
committerAdam Spragg <adam@spra.gg>2022-12-06 14:38:16 +0000
commit3d74618a696287e2aec6352894b9c75e04cf7817 (patch)
tree3d7ebad532008ad560b7f59a53af993f8ffd4642
parent8df47f52f8cdcb9602c72f19d2a4824d0a03164b (diff)
Solve puzzle 6 part 1
-rw-r--r--6.c32
-rw-r--r--makefile1
2 files changed, 33 insertions, 0 deletions
diff --git a/6.c b/6.c
new file mode 100644
index 0000000..f36c934
--- /dev/null
+++ b/6.c
@@ -0,0 +1,32 @@
+
+#include <stdio.h>
+
+
+int
+main()
+{
+ char buf[4];
+ int c, n = 0;
+
+ while ((c = fgetc(stdin)) != EOF) {
+ buf[n % 4] = c;
+ ++n;
+
+ if (n >= 4
+ && buf[0] != buf[1] && buf[0] != buf[2] && buf[0] != buf[3]
+ && buf[1] != buf[2] && buf[1] != buf[3] && buf[2] != buf[3])
+ {
+ break;
+ }
+ }
+
+ if (c == EOF) {
+ printf("No marker read in %d bytes\n", n);
+ return 1;
+ }
+
+ printf("Marker read after %d bytes\n", n);
+
+ return 0;
+}
+
diff --git a/makefile b/makefile
index ef0b2f0..b00a363 100644
--- a/makefile
+++ b/makefile
@@ -7,6 +7,7 @@ all: bin \
bin/3a bin/3b \
bin/4a bin/4b \
bin/5 \
+ bin/6 \
bin:
mkdir -p $@