-
Notifications
You must be signed in to change notification settings - Fork 0
/
day6.c
54 lines (43 loc) · 1.06 KB
/
day6.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// ----------------------------------------------------------------------------
// Advent of Code 2022 - Day 6
// Dale Whinham
//
// $ gcc day6.c -Wall -Wextra -Wpedantic -Werror -o day6
// $ ./day6
// ----------------------------------------------------------------------------
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include "util.h"
#define PART_TWO
#ifdef PART_TWO
#define MARKER_LEN 14
#else
#define MARKER_LEN 4
#endif
#define INPUT_FILE "input/day6.txt"
static inline bool all_unique(const char* string, size_t len)
{
for (size_t i = 0; i < len; ++i)
{
for (size_t j = i + 1; j < len; ++j)
{
if (string[i] == string[j])
return false;
}
}
return true;
}
int main()
{
size_t size, offset = 0;
char* message = read_file(INPUT_FILE, &size);
// Find unique marker
while (!all_unique(&message[offset], MARKER_LEN))
++offset;
offset += MARKER_LEN;
printf("Marker offset: %zu\n", offset);
free(message);
return EXIT_SUCCESS;
}