day 23 optimize again
[aoc_eblake.git] / 2016 / advent15.c
blob5b6032737d4879d85a631ebcd80c200687c71702
1 #define _GNU_SOURCE 1
2 #include <stdio.h>
3 #include <string.h>
4 #include <stdlib.h>
5 #include <unistd.h>
7 #define MAX 7 // cheat, by pre-inspecting input
9 int
10 main (int argc, char **argv)
12 int sizes[MAX] = { 0 };
13 int offsets[MAX] = { 0 };
14 ssize_t nread;
15 size_t len = 0;
16 char *line = NULL;
17 int count = 0;
18 while ((nread = getline(&line, &len, stdin)) >= 0) {
19 char *p = strstr (line, "has") + 3;
20 sizes[count] = atoi (p);
21 p = strstr (line, "at position") + 11;
22 offsets[count] = atoi (p);
23 count++;
25 sizes[count++] = 11;
26 printf ("read/synthesized details for %d discs\n", count);
27 int time = -1;
28 retry:
29 time++;
30 for (int i = 0; i < count; i++)
31 if ((time + offsets[i] + i) % sizes[i])
32 goto retry;
33 printf ("start at time %d\n", time - 1);
34 return 0;