92a1b8ae972e27c0efd07b91e2adaef3c4472633
[advent21.git] / 06a.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4
5 int main()
6 {
7 char buf[1000];
8 if (fgets(buf, 1000, stdin) == NULL)
9 return 1;
10 long fish0[9] = {0};
11 long fish1[9] = {0};
12 long *this = &fish0[0];
13 long *that = &fish1[0];
14
15 char *p = strtok(buf, ",");
16 this[atoi(p)]++;
17 while ((p = strtok(NULL, ",")) != NULL)
18 this[atoi(p)]++;
19
20 for (long day = 0; day<80; day++) {
21 that[8] = this[0];
22 for (long i = 0; i<8; i++)
23 that[i] = this[i+1];
24 that[6] += this[0];
25 long *tmp = this;
26 this = that;
27 that = tmp;
28 }
29
30 long sum = 0;
31 for (long i = 0; i<=8; i++)
32 sum += this[i];
33 printf("%lu\n", sum);
34 }