Skip to content Skip to sidebar Skip to footer

Find All Possible Combinations That Overlap By End And Start

In the post find all combinations with non-overlapped regions (code pasted below), the function is given a set of tuples and it recursively finds every possible collection of tuple

Solution 1:

Change >= to >. Right now, the code skips over the "next" tuple if the left index value of the "next" tuple is less than or equal to the right index value of the "current" tuple. It finds the first tuple that has a left index value that is strictly greater than the current tuple's right index value.

defnonovl(l, idx, right, ll):
    if idx == len(l):
        if ll:
            print(ll)
        returnnext = idx + 1whilenext < len(l) and right > l[next][0]:
        next += 1
    nonovl(l, next, right, ll)

    next = idx + 1
    right = l[idx][1]
    whilenext < len(l) and right > l[next][0]:
        next += 1
    nonovl(l, next, right, ll + str(l[idx]))

Output:

(6.0, 7.25)
(2.5, 4.5)
(2.5, 4.5)(6.0, 7.25)
(2.0, 5.75)
(2.0, 5.75)(6.0, 7.25)
(2.0, 4.0)
(2.0, 4.0)(6.0, 7.25)
(0.0, 4.0)
(0.0, 4.0)(6.0, 7.25)
(0.0, 2.0)
(0.0, 2.0)(6.0, 7.25)
(0.0, 2.0)(2.5, 4.5)
(0.0, 2.0)(2.5, 4.5)(6.0, 7.25)
(0.0, 2.0)(2.0, 5.75)
(0.0, 2.0)(2.0, 5.75)(6.0, 7.25)
(0.0, 2.0)(2.0, 4.0)
(0.0, 2.0)(2.0, 4.0)(6.0, 7.25)

Post a Comment for "Find All Possible Combinations That Overlap By End And Start"