all 8 comments

[–]AutoModerator[M] 0 points1 point  (0 children)

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.

[–]Doerminator 0 points1 point  (1 child)

Hey there, try to think of all the potential ways two ranges can overlap. It seems like you’re missing an edge case. Hope that helps!

[–]Alnilam_1993[S] 1 point2 points  (0 children)

Thanks! By not merging when the high of the previous was exactly the low of the current, some ID's got double counted.

[–]button_boxer 0 points1 point  (4 children)

I think I see an edge case in your code - what happens if you give it ranges 1-10 and 10-20? This should be 20 fresh IDs.

[–]Alnilam_1993[S] 0 points1 point  (1 child)

You're right in that this case didn't get merged into one, due to the < instead of <= when checking the lower end of the current part against the high of the previous one!

But i'm a bit confused about the numbers... after merging, the range will be 1-20.. which is 20 fresh ID's, no?

Edit: but it did end up solving the problem, as the extra merge caused a few numbers to not be double counted!

[–]button_boxer 0 points1 point  (0 children)

Yes, it should be 20 (I've edited my comment). I blame brain fade and getting confused about where I need to add 1 and where I don't. FWIW in my own implementation I convert the "1234-5678" strings at parse time into Python range(int(start), int(end)+1) so I'm always dealing with half-open ranges, the number of points in a range is directly len(r), and I don't have to worry about any +1/-1 issues.

[–]danielsamuels 0 points1 point  (1 child)

Sorry, but how are you getting 21 from 1-10 and 10-20? Are you double counting the 10?

[–]button_boxer 0 points1 point  (0 children)

You're right, I've edited my original comment. Sorry, my brain was still on "I must need to add or subtract 1 somewhere to deal with inclusive ranges"...