From 3d74618a696287e2aec6352894b9c75e04cf7817 Mon Sep 17 00:00:00 2001 From: Adam Spragg Date: Tue, 6 Dec 2022 14:38:16 +0000 Subject: Solve puzzle 6 part 1 --- 6.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 6.c (limited to '6.c') 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 + + +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; +} + -- cgit v1.2.1