-
-
Save zid/76a43308a7a5cf667186fd87e6487200 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
int main(void) | |
{ | |
char line[1024]; | |
FILE *f; | |
int count = 0, count2 = 0; | |
f = fopen("day4.txt", "r"); | |
while(1) | |
{ | |
if(!fgets(line, 128, f)) | |
break; | |
int a = -1, b = -1, c = -1, d = -1; | |
sscanf(line, "%d-%d,%d-%d\n", &a, &b, &c, &d); | |
if((c >= a && d <= b) || (c <= a && d >= b)) | |
{ | |
printf("%d-%d,%d-%d matches\n", a, b, c, d); | |
count++; | |
} | |
if((c >= a && c <= b) || (d >= a && d <= b) || (a >= c && b <= d)) | |
{ | |
printf("%d-%d,%d-%d overlaps\n", a, b, c, d); | |
count2++; | |
} | |
} | |
printf("Count: %d, count2: %d\n", count, count2); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment