Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def chunks(n, l):
- for i in xrange(0, len(l), n):
- yield l[i:i+n]
- DAYS_PER_MONTH = [ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ]
- def date_to_days(date):
- splitted = date.split('/')
- return sum(DAYS_PER_MONTH[1:int(splitted[0])]) + int(splitted[1])
- def max_occupancy(fpath):
- guests = map(
- lambda x: ( x[0], date_to_days(x[1]), date_to_days(x[2]) ),
- chunks(3,
- open(fpath).read().split()
- )
- )
- current_guests = []
- max_current = 0
- for entry in guests:
- current_guests = filter(lambda x: x >= entry[2], current_guests) + [ entry[2] ]
- if len(current_guests) > max_current:
- max_current = len(current_guests)
- return max_current
- print(max_occupancy("text.txt"))
Advertisement
Add Comment
Please, Sign In to add comment