-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday6a.c
57 lines (56 loc) · 1.23 KB
/
day6a.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
55
56
57
#include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <math.h>
#include "split.h"
#include <stdint.h>
#define WINDOW_SIZE 4
int main(int argc, char** argv){
struct stat statbuf;
int fd = open("input", O_RDONLY);
fstat(fd, &statbuf);
size_t filesize = statbuf.st_size;
char* input_map = mmap(NULL, filesize, PROT_READ, MAP_SHARED, fd, 0);
close(fd);
char mapping[128];
memset(mapping, 0, 128);
char moved = 0;
char* beginp = input_map;
char* nextp = input_map + WINDOW_SIZE;
char remaining = WINDOW_SIZE;
do_remaining:
while (remaining){
mapping[*(nextp - remaining--)]++;
moved++;
}
int t = moved;
while(moved){
if (mapping[*(nextp - moved)] == 1){
t--;
}
moved--;
}
if (!t){
printf("found soln %ld\n", nextp - input_map);
}
loopback:
//remaining = moved = 0;
mapping[*beginp++]--;
mapping[*nextp]++;
if (mapping[*nextp++] == 1){
for(unsigned int i = 0x20; i < 0x7E; i+=8){
if( (*(uint64_t*)(mapping+i)) & 0xFEFEFEFEFEFEFEFE){
goto loopback;
}
}
printf("done %ld\n", nextp - input_map);
goto done;
}
goto loopback;
done:
munmap(input_map, filesize);
return 0;
}