repositories
/
advent21.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
day 12 part two wrong, day 13 done
[advent21.git]
/
06a.c
diff --git
a/06a.c
b/06a.c
index
c9152c6
..
e2634d2
100644
(file)
--- a/
06a.c
+++ b/
06a.c
@@
-4,10
+4,11
@@
int main()
{
int main()
{
- char buf[1000];
- if (fgets(buf, 1000, stdin) == NULL)
- return 1;
+ char *buf = NULL;
+ size_t len = 0;
long fish[9] = {0};
long fish[9] = {0};
+
+ getline(&buf, &len, stdin);
char *p = strtok(buf, ",");
fish[atoi(p)]++;
while ((p = strtok(NULL, ",")) != NULL)
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];
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]);
}
}