diff options
author | June McEnroe <june@causal.agency> | 2020-12-02 00:09:58 -0500 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2020-12-02 00:09:58 -0500 |
commit | 6d176569fd64464f1529eecc522b4bfebeeff18f (patch) | |
tree | cd4451bae4eb616e276b592e061cb3f22bddcadb | |
parent | Solve day 2 part 1 (diff) | |
download | aoc-6d176569fd64464f1529eecc522b4bfebeeff18f.tar.gz aoc-6d176569fd64464f1529eecc522b4bfebeeff18f.zip |
Solve day 2 part 2
Diffstat (limited to '')
-rw-r--r-- | 2020/day02.c | 8 |
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); } |