gmo61520

Untitled

Feb 16th, 2016
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. def chunks(n, l):
  2. for i in xrange(0, len(l), n):
  3. yield l[i:i+n]
  4.  
  5. DAYS_PER_MONTH = [ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ]
  6. def date_to_days(date):
  7. splitted = date.split('/')
  8. return sum(DAYS_PER_MONTH[1:int(splitted[0])]) + int(splitted[1])
  9.  
  10. def max_occupancy(fpath):
  11. guests = map(
  12. lambda x: ( x[0], date_to_days(x[1]), date_to_days(x[2]) ),
  13. chunks(3,
  14. open(fpath).read().split()
  15. )
  16. )
  17.  
  18. current_guests = []
  19. max_current = 0
  20. for entry in guests:
  21. current_guests = filter(lambda x: x >= entry[2], current_guests) + [ entry[2] ]
  22. if len(current_guests) > max_current:
  23. max_current = len(current_guests)
  24. return max_current
  25.  
  26. print(max_occupancy("text.txt"))
Advertisement
Add Comment
Please, Sign In to add comment