summary refs log tree commit diff homepage
diff options
context:
space:
mode:
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);
 }