From 2a69c8ba67636604c6140f43557bcb7678aa7fef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dobos=20=C3=81d=C3=A1m?= Date: Sat, 10 Dec 2022 18:54:10 +0100 Subject: [PATCH] Small improvements to day6 --- day6/marker | Bin 16160 -> 16160 bytes day6/marker.c | 9 +++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/day6/marker b/day6/marker index 213c009f6cc59fa309b6e0b644bc6e708433a84d..8494663a234389b64e2857e133e26e77691eca1d 100755 GIT binary patch delta 286 zcmZ2bx1er=10!b$BLf(OZ1!Z-XB1RWfNDQkoyD4ZfT1+lf5NB+d+^L|> zxMK1~1#!s*@BjaI04jh186cwvh&N7ts36ZcXELLrJmclfii+txn-}OlU}g-M+-T^| jsId8@p*a_$>|{n8eNKcIEp5y>GZY|3Wo)jrSo5Az>B#){3ILe;!Zs+n92jMB{3EfAW8*@O@MgD!)d#2HUc{;43(xMi}WqCDg4&6bMkJd+PFNo-!A`+%9zVsfLQJ0r*D ilZNJ8j2x30ZS*-29<;PE=L}E)ngav@n=5UWGXVg;QB>yu diff --git a/day6/marker.c b/day6/marker.c index 44addda..c5b7576 100644 --- a/day6/marker.c +++ b/day6/marker.c @@ -2,9 +2,10 @@ #include #include -#define WINDOW_SIZE 14 +#define max(a,b) (a >= b ? a : b) #define START_OF_PACKET 4 #define START_OF_MESSAGE 14 +#define WINDOW_SIZE max(START_OF_PACKET, START_OF_MESSAGE) void shift(char*, char); int unique(char*, int n); @@ -19,14 +20,14 @@ int main() { if (charNum > START_OF_PACKET - 1 && !result && unique(buf + (WINDOW_SIZE - START_OF_PACKET), START_OF_PACKET)) { result = charNum; } - if (charNum > START_OF_MESSAGE - 1 && !result2 && unique(buf, START_OF_MESSAGE)) { + if (charNum > START_OF_MESSAGE - 1 && !result2 && unique(buf + (WINDOW_SIZE - START_OF_MESSAGE), START_OF_MESSAGE)) { result2 = charNum; } charNum++; } - printf("%i\n", result); - printf("%i\n", result2); + printf("Packet: %i\n", result); + printf("Message: %i\n", result2); } void shift(char* buf, char c) {