# INTERVALS LIBRARY from math import floor, ceil from tools import min_max def reunion_inter(inter, a, b): a, b = min_max(a, b) a, b = floor(a), ceil(b) for i in range(0, len(inter), 2): if a <= inter[i+1] + 1: if b >= inter[i] - 1: inter[i:i+2] = [min(a, inter[i]), max(b, inter[i+1])] else: return inter[:i] + [a, b] + inter[i:] return inter + [a, b] def inclus_inter(inter, a, b): a, b = min_max(a, b) for i in range(0, len(inter), 2): if a <= inter[i+1]: return a >= inter[i] and b <= inter[i+1] return 0 def remove_hidden_by_inter(a, b, inter): a, b = min_max(a, b) for i in range(0, len(inter), 2): if a < inter[i] and b >= inter[i] and b <= inter[i+1]: b = inter[i] for i in range(len(inter) - 2, -2, -2): if a >= inter[i] and a <= inter[i+1] and b > inter[i+1]: a = inter[i+1] return a, b