Skip to content

Instantly share code, notes, and snippets.

@jkoppel
Created Feb 9, 2018
Embed
What would you like to do?
class interval:
def init(low, hi):
self.low = low
self.hi = hi
# bad version
def intersect(oth):
if self.low <= oth.low:
if self.hi < oth.low:
return interval(0,0)
elif: oth.hi <= self.hi:
return self
else:
return interval(oth.min,self.max)
elif self.hi >= oth.hi:
if self.low > oth.hi:
return interval(0,0)
elif: oth.low >= self.low:
return oth
else:
return interval(oth.max,self.min)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment