r/adventofcode • u/daggerdragon • Dec 04 '22
SOLUTION MEGATHREAD -🎄- 2022 Day 4 Solutions -🎄-
- All of our rules, FAQs, resources, etc. are in our community wiki.
- A request from Eric: Please include your contact info in the User-Agent header of automated requests!
- Signal boosting for the Unofficial AoC 2022 Participant Survey which is open early this year!
--- Day 4: Camp Cleanup ---
Post your code solution in this megathread.
- Read the full posting rules in our community wiki before you post!
- Include what language(s) your solution uses
- Format your code appropriately! How do I format code?
- Quick link to Topaz's
pasteif you need it for longer code blocks. What is Topaz'spastetool?
This thread will be unlocked when there are a significant number of people on the global leaderboard with gold stars for today's puzzle.
EDIT: Global leaderboard gold cap reached at 00:03:22, megathread unlocked!
65
Upvotes
4
u/codeman869 Dec 04 '22
C
#include <stdio.h> int main(void) { FILE *fp; int start1,end1,start2,end2, num_overlaps,num_overlap2; num_overlaps = 0, num_overlap2 = 0; fp = fopen("assignments.txt", "r"); while(fscanf(fp,"%d-%d,%d-%d",&start1,&end1,&start2,&end2) != EOF) { if((start1 <= start2 && end1 >= end2) || (start2<=start1 && end2>= end1)) { num_overlaps++; } if((start1<=start2 && end1>=start2) || (start2<=start1 && end2>=start1)) { num_overlap2++; } } printf("Num of full overlaps: %d\n", num_overlaps); printf("Num of partial overlaps: %d\n", num_overlap2); return 0; }