X-Git-Url: https://git.martlubbers.net/?a=blobdiff_plain;f=06a.c;h=e2634d21ba73e026ecccfd2f7be314b99e793a36;hb=967152a3319e0207e16901ecc0344edaf8c8193e;hp=c9152c675909172c9243f0dd7e57d61ff3e5af38;hpb=2d015db00d7612786a98db0cdfda291b6dc08389;p=advent21.git diff --git a/06a.c b/06a.c index c9152c6..e2634d2 100644 --- a/06a.c +++ b/06a.c @@ -4,10 +4,11 @@ int main() { - char buf[1000]; - if (fgets(buf, 1000, stdin) == NULL) - return 1; + char *buf = NULL; + size_t len = 0; long fish[9] = {0}; + + getline(&buf, &len, stdin); char *p = strtok(buf, ","); fish[atoi(p)]++; while ((p = strtok(NULL, ",")) != NULL) @@ -16,8 +17,7 @@ int main() for (long day = 0; day<80; day++) fish[(day+7) % 9] += fish[day%9]; - long sum = 0; - for (long i = 0; i<=8; i++) - sum += fish[i]; - printf("%lu\n", sum); + for (long i = 1; i<=8; i++) + fish[0] += fish[i]; + printf("%ld\n", fish[0]); }