Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. movies = [(1, 2, 'K1'), (2, 4, 'K2'), (8, 11, 'K2'), (11, 12, 'K2'), (9, 11, 'K1'), (4, 9, 'K3'), (1, 3, 'K1'),
  2. (2, 4, 'K3'), (3, 5, 'K1'), (5, 7, 'K1'), (7, 8, 'K2'), (7, 9, 'K1'), (9, 11, 'K3')]
  3.  
  4.  
  5. def get_beginning_hour(data):
  6. return data[0]
  7.  
  8.  
  9. movies.sort(key=get_beginning_hour)
  10. print(f'Posortowane filmy: {movies}')
  11.  
  12. i = 0
  13. j = 0
  14. output_cinemas = []
  15. output_scores = []
  16.  
  17. for movie1 in movies:
  18. print(f'Film od którego zaczynamy sprawdzanie: {movie1}')
  19. cinemas = [movie1]
  20. score = 1
  21. end = movie1[1]
  22.  
  23. for movie2 in movies:
  24. if i != j:
  25. print(movie2)
  26. if movie2[0] >= end:
  27. print(f'Warunek spełniony, dodajemy {movie2} do listy')
  28. end = movie2[1]
  29. score += 1
  30. cinemas.append(movie2)
  31. j += 1
  32.  
  33. output_cinemas.append(cinemas)
  34. output_scores.append(score)
  35. print(f'Koniec iteracji, ciąg filmów {cinemas} osiągnął wynik {score}')
  36. j = 0
  37. i += 1
  38.  
  39. max_score = max(output_scores)
  40. result_index = output_scores.index(max_score)
  41.  
  42. result = output_cinemas[result_index]
  43. print(f'Najlepsza kombinacja: {result}, obejrzymy {max_score} filmów')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement