Small improvements to day6

This commit is contained in:
Dobos Ádám
2022-12-10 18:54:10 +01:00
parent 1ff9a240fe
commit 2a69c8ba67
2 changed files with 5 additions and 4 deletions

View File

Binary file not shown.

View File

@@ -2,9 +2,10 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#define WINDOW_SIZE 14 #define max(a,b) (a >= b ? a : b)
#define START_OF_PACKET 4 #define START_OF_PACKET 4
#define START_OF_MESSAGE 14 #define START_OF_MESSAGE 14
#define WINDOW_SIZE max(START_OF_PACKET, START_OF_MESSAGE)
void shift(char*, char); void shift(char*, char);
int unique(char*, int n); 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)) { if (charNum > START_OF_PACKET - 1 && !result && unique(buf + (WINDOW_SIZE - START_OF_PACKET), START_OF_PACKET)) {
result = charNum; 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; result2 = charNum;
} }
charNum++; charNum++;
} }
printf("%i\n", result); printf("Packet: %i\n", result);
printf("%i\n", result2); printf("Message: %i\n", result2);
} }
void shift(char* buf, char c) { void shift(char* buf, char c) {