diff options
author | June McEnroe <june@causal.agency> | 2020-12-07 01:55:57 -0500 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2020-12-07 01:55:57 -0500 |
commit | 8e6fd26e42c80bafb67d6fbb4cc28f7a89427dec (patch) | |
tree | cb11067baa8a14f94aa9afccc0f69ab601b2405c | |
parent | Solve day 7 part 1 (diff) | |
download | aoc-8e6fd26e42c80bafb67d6fbb4cc28f7a89427dec.tar.gz aoc-8e6fd26e42c80bafb67d6fbb4cc28f7a89427dec.zip |
Solve day 7 part 2
Diffstat (limited to '')
-rw-r--r-- | 2020/day07.c | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/2020/day07.c b/2020/day07.c index 3d97d5f..7445259 100644 --- a/2020/day07.c +++ b/2020/day07.c @@ -37,6 +37,16 @@ static bool canContain(struct Bag *bag, const char *adj, const char *col) { } return false; } +static int containsCount(struct Bag *bag) { + int count = 0; + for (int i = 0; i < 4; ++i) { + if (!bag->cons[i].adj[0]) break; + count += bag->cons[i].cnt; + count += bag->cons[i].cnt + * containsCount(findBag(bag->cons[i].adj, bag->cons[i].col)); + } + return count; +} int main(void) { while (EOF != scanf("%s %s bags contain", bags[len].adj, bags[len].col)) { for ( @@ -57,4 +67,5 @@ int main(void) { if (canContain(&bags[i], "shiny", "gold")) count++; } printf("%d\n", count); + printf("%d\n", containsCount(findBag("shiny", "gold"))); } |