-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Labels
Description
This idea was inspired by this video. I thought, couldn't Spackle have a way to say, given a collection of ints, create all the Ranges that represent the bounds of the values in the array.
For example, if I have [3, 1, 7, 5, 2], I should get (1, 4), (5, 6), (7, 8)
- Basically, for each number x:
- If there are no ranges, add (x, x)
- For each range,
- If x is in the range, end for
- If not, but it is "next to" the start or the end (i.e. (3, 7) and x is 7, 7 is "next to" 6, which is the inclusive end, or (3, 7) and x is 2, 2 is "next to" 3), update the range on the start or end side
- Else, move on
- If I never found a condition, create a new range, (x, x + 1)
Also, consider how much the list of ranges should be allocated as a best initial guess. For example, if you are given an array of X elements, at most you'd create 20 ranges. Not sure if there's any meaningful heuristic to use here to try and optimize the initial list range allocation.
Reactions are currently unavailable