summary refs log tree commit diff homepage
path: root/2020
diff options
context:
space:
mode:
Diffstat (limited to '2020')
-rw-r--r--2020/day07.c11
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")));
 }
oe 2020-09-12Move /opt/local back, cheat port select to use system manJune McEnroe 2020-09-12Move /opt/local behind /usr againJune McEnroe 2020-09-12Enable toc in cgit renderings of man pagesJune McEnroe 2020-09-11Install mandoc on macOSJune McEnroe 2020-09-11Rewrite install script yet againJune McEnroe 2020-09-11Remove NetBSD from install scriptJune McEnroe 2020-09-11Use MacPorts rather than pkgsrcJune McEnroe 2020-09-11Add debian VM name to sshJune McEnroe 2020-09-11Add influencer tweetJune McEnroe 2020-09-10Add The Kingdom of GodsJune McEnroe 2020-09-07Add SunglassesJune McEnroe 2020-09-06Add Between the BreathsJune McEnroe 2020-09-04Open /dev/tty in nudgeJune McEnroe 2020-09-04Add nudgeJune McEnroe 2020-09-03Build fbclock with -lzJune McEnroe 2020-08-29Add tweets from retweetsJune McEnroe