This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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