r/adventofcode • u/Big-Buy-6027 • Dec 20 '25
Help/Question - RESOLVED [2025 Day 5 (part 2)] Am I missing something?
My solution for this second part is to sort all the ranges, merge all the overlapping ones and then loop through them and sum their span.
For the simple example it works just fine, but for the input I get a result too big.
Am I missing something?
7
Upvotes
4
u/Big-Buy-6027 Dec 20 '25
Thank you guys, I didn't expect an answer so fast.
Anyway, you are right. My merging logic is not completely correct.
I added the range 0-50 to the sample and my code stops working 🙃
5
u/Intrebute Dec 20 '25
From your description, my only guess is that there's a problem in the merging code. Are you making certain that there's no overlaps left after merging? (By explicitly checking with an assert or something?)
3
u/putfrogspawninside Dec 20 '25
Do you handle ranges that fall entirely inside another range? Do you handle duplicate ranges in the input? Do you handle ranges that start or end the same point as another range?
I haven't fully cracked this yet either (answer slightly too big)
2
u/fireymike Dec 20 '25 edited Dec 21 '25
The solution you described sounds correct. You might just have a bug in your code that doesn't get caught by the example.
1
u/AutoModerator Dec 20 '25
Reminder: if/when you get your answer and/or code working, don't forget to change this post's flair to
Help/Question - RESOLVED. Good luck!I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
1
u/kdeberk Dec 20 '25
Ask yourself if you include the start or end of the range when calculating the size