summaryrefslogtreecommitdiff
path: root/2022/day04/main2.c
diff options
context:
space:
mode:
authorOrangerot <purple@orangerot.dev>2022-12-17 01:16:18 +0100
committerOrangerot <purple@orangerot.dev>2022-12-17 01:16:18 +0100
commit6596b48113ced669b206d2e1f1e8ba6edcba88a2 (patch)
tree02c7d01783390862d989df6c91aff968e03dd415 /2022/day04/main2.c
adv2022 first 8 days
Diffstat (limited to '2022/day04/main2.c')
-rw-r--r--2022/day04/main2.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/2022/day04/main2.c b/2022/day04/main2.c
new file mode 100644
index 0000000..d26bdb6
--- /dev/null
+++ b/2022/day04/main2.c
@@ -0,0 +1,18 @@
+#include <stdio.h>
+
+int main()
+{
+ int a1,a2,b1,b2;
+ int overlaps = 0;
+ while (scanf("%d-%d,%d-%d", &a1, &a2, &b1, &b2) != EOF)
+ {
+ // printf("%d-%d,%d-%d", a1, a2, b1, b2);
+ if (
+ ((a1 >= b1) && (a2 <= b2)) || ((b1 >= a1) && (b2 <= a2)) ||
+ ((a1 <= b1) && (a2 >= b1) || (a1 <= b2) && (a2 >= b2) )
+ ) {
+ overlaps++;
+ }
+ }
+ printf("%d\n", overlaps);
+}