summaryrefslogtreecommitdiff
path: root/2022/day6/day6.c
diff options
context:
space:
mode:
authornekineki <nekineki@nekineki.net>2022-12-11 14:47:27 +0100
committernekineki <nekineki@nekineki.net>2022-12-11 14:50:32 +0100
commitfe75c10e350743a1c078f065d69556fecf825ca5 (patch)
tree956556a564c9329346dc9d8b1535dc5e365f3d55 /2022/day6/day6.c
parenta74d2dc54aef546664bcc8c81eb8e01a93e94391 (diff)
move files around, update paths
Diffstat (limited to '2022/day6/day6.c')
-rw-r--r--2022/day6/day6.c54
1 files changed, 0 insertions, 54 deletions
diff --git a/2022/day6/day6.c b/2022/day6/day6.c
deleted file mode 100644
index 13d5c04..0000000
--- a/2022/day6/day6.c
+++ /dev/null
@@ -1,54 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <string.h>
-#include "../util.h"
-
-// char filename[] = "ref.txt";
-char filename[] = "pzl.txt";
-
-#define BUF_LEN 10000
-u8 buf[BUF_LEN];
-#define NAH_LEN 26
-u8 not_a_hashmap[NAH_LEN];
-
-s32 solve(u32 n)
-{
- int fd = open(filename, O_RDONLY);
- u32 data_len = read(fd, buf, LEN(buf));
- if (data_len == LEN(buf)) {
- printf("buffer probably not big enough\n");
- exit(1);
- }
-
- for (u32 i = n; i < data_len; ++i) {
- memset(not_a_hashmap, 0x00, LEN(not_a_hashmap));
-
- for (u32 j = 1; j <= n; ++j) {
- u32 index = (buf[i-j]-'a');
- if (index >= NAH_LEN) {
- printf("nah too small\n");
- exit(1);
- }
- not_a_hashmap[index] = 1;
- }
-
- u32 sum = 0;
- for (u32 j = 0; j < NAH_LEN; ++j) {
- sum += not_a_hashmap[j];
- }
- if (sum == n) {
- return i;
- }
-
- }
- return -1;
-}
-
-int main()
-{
- printf("res1: %d\n", solve(4));
- printf("res2: %d\n", solve(14));
-}
-