Small improvements to day6
This commit is contained in:
BIN
day6/marker
BIN
day6/marker
Binary file not shown.
@@ -2,9 +2,10 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#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) {
|
||||
|
||||
Reference in New Issue
Block a user