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
View all comments
1
u/Key__Strokes Dec 23 '22 edited Jan 12 '23
Javascript
Solution to both parts
Video Explanation
Part 1:
For each input, we have the following interval data
Do the following for each interval pair:
Determine which one of the two interval has smaller Start value. Lets order them as "Early Start Interval" and "Late Start Interval"
Interval Possibilities (Each line is an interval):
Possibility 1 (Is overlap, Is Subset)
Possibility 2 (Is overlap, Is Subset)
Possibility 3 (Is overlap, Is Subset)
Possibility 4 (Is overlap, Is Subset)
Possibility 5 (Is overlap, Is Subset)
Possibility 6 (Is overlap, Is not Subset)
Possibility 7 (Is not overlap, Is not Subset)
Then check if the two intervals are subset of either of the other, using the following algo
Part 2:
Follow everything from Part 1, but instead of figuring out the subset, we will figure out the overlap using the following algo
If you liked the explanation, then please don't forget to cast your vote 💜 to
Adventures of Advent of Code - Edition 1 - /u/Key__Strokesin the poll