summary refs log tree commit diff homepage
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-12-02 00:09:58 -0500
committerJune McEnroe <june@causal.agency>2020-12-02 00:09:58 -0500
commit6d176569fd64464f1529eecc522b4bfebeeff18f (patch)
treecd4451bae4eb616e276b592e061cb3f22bddcadb
parentSolve day 2 part 1 (diff)
downloadaoc-6d176569fd64464f1529eecc522b4bfebeeff18f.tar.gz
aoc-6d176569fd64464f1529eecc522b4bfebeeff18f.zip
Solve day 2 part 2
Diffstat (limited to '')
-rw-r--r--2020/day02.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/2020/day02.c b/2020/day02.c
index 597efde..793396c 100644
--- a/2020/day02.c
+++ b/2020/day02.c
@@ -1,7 +1,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 int main(void) {
-	int valid = 0;
+	int valid1 = 0, valid2 = 0;
 	int l, u;
 	char c, p[256];
 	while (EOF != scanf("%d-%d %c: %s\n", &l, &u, &c, p)) {
@@ -9,7 +9,9 @@ int main(void) {
 		for (int i = 0; p[i]; ++i) {
 			if (p[i] == c) n++;
 		}
-		if (n >= l && n <= u) valid++;
+		if (n >= l && n <= u) valid1++;
+		if ((p[l-1] == c) ^ (p[u-1] == c)) valid2++;
 	}
-	printf("%d\n", valid);
+	printf("%d\n", valid1);
+	printf("%d\n", valid2);
 }