1import math
2
3
4class Candy:
5
6 def __init__(self, mass: int, uranium: float):
7 self.mass = mass
8 self.uranium = uranium
9
10 def get_uranium_quantity(self):
11 return self.mass * self.uranium
12
13 def get_mass(self):
14 return self.mass
15
16
17class Person:
18
19 def __init__(self, position: tuple):
20 self.position = position
21
22 def get_position(self):
23 return self.position
24
25 def set_position(self, new_position: tuple):
26 self.position = new_position
27
28
29class Kid(Person):
30
31 def __init__(self, position: tuple, initiative: int):
32 super().__init__(position)
33 self.initiative = initiative
34 self.candy_basket = []
35 self.hosts_visited = set()
36
37 def get_initiative(self):
38 return self.initiative
39
40 def add_candy(self, candy: Candy):
41 self.candy_basket.append(candy)
42
43 def is_critical(self):
44 current_uranium = 0
45 candy: Candy
46 for candy in self.candy_basket:
47 current_uranium += candy.get_uranium_quantity()
48
49 if current_uranium > 20:
50 return True
51 return False
52
53 def get_hosts_visited(self):
54 return self.hosts_visited
55
56 def visit_host(self, host):
57 self.hosts_visited.add(host)
58
59
60class Host(Person):
61
62 def __init__(self, position: tuple, candies: list):
63 super().__init__(position)
64 self.candies = []
65 for candy_tuple in candies:
66 self.candies.append(Candy(candy_tuple[0], candy_tuple[1]))
67
68 def remove_candy(self, filter_func):
69 if not self.candies:
70 return None
71
72 to_remove = filter_func(self.candies)
73 if to_remove is None:
74 return None
75 self.candies.remove(to_remove)
76
77 return to_remove
78
79
80class FluxCapacitor:
81
82 def __init__(self, participants: set):
83
84 self.kids = []
85 self.hosts = []
86 person: Person
87 for person in participants:
88 if type(person) == Kid:
89 self.kids.append(person)
90 else:
91 self.hosts.append(person)
92
93 self.kids.sort(key=lambda x: x.initiative, reverse=True)
94
95 def get_victim(self):
96 victims = set()
97
98 if len(self.kids) == 0:
99 return None
100
101 loop = True
102
103 while loop:
104
105 kid: Kid
106 for kid in self.kids:
107 closest_host = self._find_closest_host_to_kid(kid)
108 if closest_host is None:
109 loop = False
110 break
111
112 given = closest_host.remove_candy(self.get_biggest_candy)
113 if given is not None:
114 kid.add_candy(given)
115
116 if kid.is_critical():
117 victims.add(kid)
118 loop = False
119
120 kid.visit_host(closest_host)
121 kid.set_position(closest_host.get_position())
122
123
124 if victims:
125 return victims
126 return None
127
128 def _find_closest_host_to_kid(self, kid: Kid):
129 current_closest_dist = -1
130 closest_host = None
131
132 host: Host
133 for host in self.hosts:
134 curr_dist = math.dist(kid.get_position(), host.get_position())
135 if host in kid.get_hosts_visited():
136 continue
137
138 if current_closest_dist < 0 or curr_dist < current_closest_dist:
139 closest_host = host
140 current_closest_dist = curr_dist
141 elif curr_dist == current_closest_dist and host.get_position() < closest_host.get_position():
142 closest_host = host
143 current_closest_dist = curr_dist
144
145 return closest_host
146
147 def get_biggest_candy(self, host_basket: set):
148 biggest = None
149
150 candy: Candy
151 for candy in host_basket:
152 if biggest is None or biggest.get_mass() < candy.get_mass():
153 biggest = candy
154
155 return biggest
156
157 def get_kids(self):
158 return self.kids
159
160
161def get_biggest_candy(candies: list):
162 biggest = None
163
164 candy: Candy
165 for candy in candies:
166 if biggest is None or biggest.get_mass() < candy.get_mass():
167 biggest = candy
168
169 return biggest
............
----------------------------------------------------------------------
Ran 12 tests in 0.000s
OK
| f | 1 | import math | f | 1 | import math |
| n | 2 | n | |||
| 3 | 2 | ||||
| 4 | 3 | ||||
| 5 | class Candy: | 4 | class Candy: | ||
| 6 | 5 | ||||
| 7 | def __init__(self, mass: int, uranium: float): | 6 | def __init__(self, mass: int, uranium: float): | ||
| 8 | self.mass = mass | 7 | self.mass = mass | ||
| 9 | self.uranium = uranium | 8 | self.uranium = uranium | ||
| 10 | 9 | ||||
| 11 | def get_uranium_quantity(self): | 10 | def get_uranium_quantity(self): | ||
| 12 | return self.mass * self.uranium | 11 | return self.mass * self.uranium | ||
| n | 13 | n | 12 | ||
| 14 | def get_mass(self): | 13 | def get_mass(self): | ||
| 15 | return self.mass | 14 | return self.mass | ||
| n | 16 | n | 15 | ||
| 17 | 16 | ||||
| 18 | class Person: | 17 | class Person: | ||
| 19 | 18 | ||||
| 20 | def __init__(self, position: tuple): | 19 | def __init__(self, position: tuple): | ||
| 21 | self.position = position | 20 | self.position = position | ||
| 22 | 21 | ||||
| 23 | def get_position(self): | 22 | def get_position(self): | ||
| 24 | return self.position | 23 | return self.position | ||
| n | 25 | n | 24 | ||
| 26 | def set_position(self, new_position: tuple): | 25 | def set_position(self, new_position: tuple): | ||
| n | 27 | self.position = new_position | n | 26 | self.position = new_position |
| 28 | 27 | ||||
| 29 | 28 | ||||
| 30 | class Kid(Person): | 29 | class Kid(Person): | ||
| 31 | 30 | ||||
| 32 | def __init__(self, position: tuple, initiative: int): | 31 | def __init__(self, position: tuple, initiative: int): | ||
| 33 | super().__init__(position) | 32 | super().__init__(position) | ||
| 34 | self.initiative = initiative | 33 | self.initiative = initiative | ||
| 35 | self.candy_basket = [] | 34 | self.candy_basket = [] | ||
| 36 | self.hosts_visited = set() | 35 | self.hosts_visited = set() | ||
| 37 | 36 | ||||
| 38 | def get_initiative(self): | 37 | def get_initiative(self): | ||
| 39 | return self.initiative | 38 | return self.initiative | ||
| n | 40 | n | 39 | ||
| 41 | def add_candy(self, candy: Candy): | 40 | def add_candy(self, candy: Candy): | ||
| 42 | self.candy_basket.append(candy) | 41 | self.candy_basket.append(candy) | ||
| 43 | 42 | ||||
| 44 | def is_critical(self): | 43 | def is_critical(self): | ||
| 45 | current_uranium = 0 | 44 | current_uranium = 0 | ||
| 46 | candy: Candy | 45 | candy: Candy | ||
| 47 | for candy in self.candy_basket: | 46 | for candy in self.candy_basket: | ||
| n | 48 | current_uranium += candy.get_uranium_quantity() | n | 47 | current_uranium += candy.get_uranium_quantity() |
| 49 | 48 | ||||
| 50 | if current_uranium > 20: | 49 | if current_uranium > 20: | ||
| 51 | return True | 50 | return True | ||
| 52 | return False | 51 | return False | ||
| n | 53 | n | 52 | ||
| 54 | def get_hosts_visited(self): | 53 | def get_hosts_visited(self): | ||
| 55 | return self.hosts_visited | 54 | return self.hosts_visited | ||
| n | 56 | n | 55 | ||
| 57 | def visit_host(self, host): | 56 | def visit_host(self, host): | ||
| 58 | self.hosts_visited.add(host) | 57 | self.hosts_visited.add(host) | ||
| n | 59 | n | 58 | ||
| 60 | 59 | ||||
| 61 | class Host(Person): | 60 | class Host(Person): | ||
| 62 | 61 | ||||
| 63 | def __init__(self, position: tuple, candies: list): | 62 | def __init__(self, position: tuple, candies: list): | ||
| 64 | super().__init__(position) | 63 | super().__init__(position) | ||
| 65 | self.candies = [] | 64 | self.candies = [] | ||
| 66 | for candy_tuple in candies: | 65 | for candy_tuple in candies: | ||
| 67 | self.candies.append(Candy(candy_tuple[0], candy_tuple[1])) | 66 | self.candies.append(Candy(candy_tuple[0], candy_tuple[1])) | ||
| 68 | 67 | ||||
| 69 | def remove_candy(self, filter_func): | 68 | def remove_candy(self, filter_func): | ||
| 70 | if not self.candies: | 69 | if not self.candies: | ||
| 71 | return None | 70 | return None | ||
| 72 | 71 | ||||
| 73 | to_remove = filter_func(self.candies) | 72 | to_remove = filter_func(self.candies) | ||
| 74 | if to_remove is None: | 73 | if to_remove is None: | ||
| 75 | return None | 74 | return None | ||
| 76 | self.candies.remove(to_remove) | 75 | self.candies.remove(to_remove) | ||
| 77 | 76 | ||||
| 78 | return to_remove | 77 | return to_remove | ||
| n | 79 | n | 78 | ||
| 80 | 79 | ||||
| 81 | class FluxCapacitor: | 80 | class FluxCapacitor: | ||
| 82 | 81 | ||||
| 83 | def __init__(self, participants: set): | 82 | def __init__(self, participants: set): | ||
| 84 | 83 | ||||
| 85 | self.kids = [] | 84 | self.kids = [] | ||
| 86 | self.hosts = [] | 85 | self.hosts = [] | ||
| 87 | person: Person | 86 | person: Person | ||
| 88 | for person in participants: | 87 | for person in participants: | ||
| 89 | if type(person) == Kid: | 88 | if type(person) == Kid: | ||
| 90 | self.kids.append(person) | 89 | self.kids.append(person) | ||
| 91 | else: | 90 | else: | ||
| 92 | self.hosts.append(person) | 91 | self.hosts.append(person) | ||
| 93 | 92 | ||||
| 94 | self.kids.sort(key=lambda x: x.initiative, reverse=True) | 93 | self.kids.sort(key=lambda x: x.initiative, reverse=True) | ||
| 95 | 94 | ||||
| 96 | def get_victim(self): | 95 | def get_victim(self): | ||
| 97 | victims = set() | 96 | victims = set() | ||
| 98 | 97 | ||||
| 99 | if len(self.kids) == 0: | 98 | if len(self.kids) == 0: | ||
| 100 | return None | 99 | return None | ||
| 101 | 100 | ||||
| 102 | loop = True | 101 | loop = True | ||
| 103 | 102 | ||||
| 104 | while loop: | 103 | while loop: | ||
| 105 | 104 | ||||
| 106 | kid: Kid | 105 | kid: Kid | ||
| 107 | for kid in self.kids: | 106 | for kid in self.kids: | ||
| 108 | closest_host = self._find_closest_host_to_kid(kid) | 107 | closest_host = self._find_closest_host_to_kid(kid) | ||
| 109 | if closest_host is None: | 108 | if closest_host is None: | ||
| 110 | loop = False | 109 | loop = False | ||
| 111 | break | 110 | break | ||
| n | 112 | n | 111 | ||
| 113 | given = closest_host.remove_candy(self.get_biggest_candy) | 112 | given = closest_host.remove_candy(self.get_biggest_candy) | ||
| 114 | if given is not None: | 113 | if given is not None: | ||
| 115 | kid.add_candy(given) | 114 | kid.add_candy(given) | ||
| n | 116 | n | 115 | ||
| 117 | if kid.is_critical(): | 116 | if kid.is_critical(): | ||
| 118 | victims.add(kid) | 117 | victims.add(kid) | ||
| 119 | loop = False | 118 | loop = False | ||
| 120 | 119 | ||||
| 121 | kid.visit_host(closest_host) | 120 | kid.visit_host(closest_host) | ||
| 122 | kid.set_position(closest_host.get_position()) | 121 | kid.set_position(closest_host.get_position()) | ||
| 123 | 122 | ||||
| n | 124 | n | 123 | ||
| 125 | if victims: | 124 | if victims: | ||
| 126 | return victims | 125 | return victims | ||
| n | 127 | return None | n | 126 | return None |
| 128 | 127 | ||||
| 129 | def _find_closest_host_to_kid(self, kid: Kid): | 128 | def _find_closest_host_to_kid(self, kid: Kid): | ||
| 130 | current_closest_dist = -1 | 129 | current_closest_dist = -1 | ||
| 131 | closest_host = None | 130 | closest_host = None | ||
| 132 | 131 | ||||
| 133 | host: Host | 132 | host: Host | ||
| 134 | for host in self.hosts: | 133 | for host in self.hosts: | ||
| 135 | curr_dist = math.dist(kid.get_position(), host.get_position()) | 134 | curr_dist = math.dist(kid.get_position(), host.get_position()) | ||
| 136 | if host in kid.get_hosts_visited(): | 135 | if host in kid.get_hosts_visited(): | ||
| 137 | continue | 136 | continue | ||
| 138 | 137 | ||||
| 139 | if current_closest_dist < 0 or curr_dist < current_closest_dist: | 138 | if current_closest_dist < 0 or curr_dist < current_closest_dist: | ||
| 140 | closest_host = host | 139 | closest_host = host | ||
| 141 | current_closest_dist = curr_dist | 140 | current_closest_dist = curr_dist | ||
| 142 | elif curr_dist == current_closest_dist and host.get_position() < closest_host.get_position(): | 141 | elif curr_dist == current_closest_dist and host.get_position() < closest_host.get_position(): | ||
| 143 | closest_host = host | 142 | closest_host = host | ||
| 144 | current_closest_dist = curr_dist | 143 | current_closest_dist = curr_dist | ||
| n | 145 | n | 144 | ||
| 146 | return closest_host | 145 | return closest_host | ||
| 147 | 146 | ||||
| 148 | def get_biggest_candy(self, host_basket: set): | 147 | def get_biggest_candy(self, host_basket: set): | ||
| 149 | biggest = None | 148 | biggest = None | ||
| 150 | 149 | ||||
| 151 | candy: Candy | 150 | candy: Candy | ||
| 152 | for candy in host_basket: | 151 | for candy in host_basket: | ||
| n | 153 | if biggest == None or biggest.get_mass() < candy.get_mass(): | n | 152 | if biggest is None or biggest.get_mass() < candy.get_mass(): |
| 154 | biggest = candy | 153 | biggest = candy | ||
| 155 | 154 | ||||
| 156 | return biggest | 155 | return biggest | ||
| 157 | 156 | ||||
| 158 | def get_kids(self): | 157 | def get_kids(self): | ||
| 159 | return self.kids | 158 | return self.kids | ||
| n | 160 | n | 159 | ||
| 161 | 160 | ||||
| 162 | def get_biggest_candy(candies: list): | 161 | def get_biggest_candy(candies: list): | ||
| n | 163 | biggest = None | n | 162 | biggest = None |
| 164 | 163 | ||||
| n | 165 | candy: Candy | n | 164 | candy: Candy |
| 166 | for candy in candies: | 165 | for candy in candies: | ||
| 167 | if biggest == None or biggest.get_mass() < candy.get_mass(): | 166 | if biggest is None or biggest.get_mass() < candy.get_mass(): | ||
| 168 | biggest = candy | 167 | biggest = candy | ||
| 169 | 168 | ||||
| t | 170 | return biggest | t | 169 | return biggest |
| Legends | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
| |||||||||
| f | 1 | import math | f | 1 | import math |
| 2 | 2 | ||||
| 3 | 3 | ||||
| 4 | 4 | ||||
| 5 | class Candy: | 5 | class Candy: | ||
| 6 | 6 | ||||
| 7 | def __init__(self, mass: int, uranium: float): | 7 | def __init__(self, mass: int, uranium: float): | ||
| 8 | self.mass = mass | 8 | self.mass = mass | ||
| 9 | self.uranium = uranium | 9 | self.uranium = uranium | ||
| 10 | 10 | ||||
| 11 | def get_uranium_quantity(self): | 11 | def get_uranium_quantity(self): | ||
| 12 | return self.mass * self.uranium | 12 | return self.mass * self.uranium | ||
| 13 | 13 | ||||
| 14 | def get_mass(self): | 14 | def get_mass(self): | ||
| 15 | return self.mass | 15 | return self.mass | ||
| 16 | 16 | ||||
| 17 | 17 | ||||
| 18 | class Person: | 18 | class Person: | ||
| 19 | 19 | ||||
| 20 | def __init__(self, position: tuple): | 20 | def __init__(self, position: tuple): | ||
| 21 | self.position = position | 21 | self.position = position | ||
| 22 | 22 | ||||
| 23 | def get_position(self): | 23 | def get_position(self): | ||
| 24 | return self.position | 24 | return self.position | ||
| 25 | 25 | ||||
| 26 | def set_position(self, new_position: tuple): | 26 | def set_position(self, new_position: tuple): | ||
| 27 | self.position = new_position | 27 | self.position = new_position | ||
| 28 | 28 | ||||
| 29 | 29 | ||||
| 30 | class Kid(Person): | 30 | class Kid(Person): | ||
| 31 | 31 | ||||
| 32 | def __init__(self, position: tuple, initiative: int): | 32 | def __init__(self, position: tuple, initiative: int): | ||
| 33 | super().__init__(position) | 33 | super().__init__(position) | ||
| 34 | self.initiative = initiative | 34 | self.initiative = initiative | ||
| 35 | self.candy_basket = [] | 35 | self.candy_basket = [] | ||
| 36 | self.hosts_visited = set() | 36 | self.hosts_visited = set() | ||
| 37 | 37 | ||||
| 38 | def get_initiative(self): | 38 | def get_initiative(self): | ||
| 39 | return self.initiative | 39 | return self.initiative | ||
| 40 | 40 | ||||
| 41 | def add_candy(self, candy: Candy): | 41 | def add_candy(self, candy: Candy): | ||
| 42 | self.candy_basket.append(candy) | 42 | self.candy_basket.append(candy) | ||
| 43 | 43 | ||||
| 44 | def is_critical(self): | 44 | def is_critical(self): | ||
| 45 | current_uranium = 0 | 45 | current_uranium = 0 | ||
| 46 | candy: Candy | 46 | candy: Candy | ||
| 47 | for candy in self.candy_basket: | 47 | for candy in self.candy_basket: | ||
| 48 | current_uranium += candy.get_uranium_quantity() | 48 | current_uranium += candy.get_uranium_quantity() | ||
| 49 | 49 | ||||
| 50 | if current_uranium > 20: | 50 | if current_uranium > 20: | ||
| 51 | return True | 51 | return True | ||
| 52 | return False | 52 | return False | ||
| 53 | 53 | ||||
| 54 | def get_hosts_visited(self): | 54 | def get_hosts_visited(self): | ||
| 55 | return self.hosts_visited | 55 | return self.hosts_visited | ||
| 56 | 56 | ||||
| 57 | def visit_host(self, host): | 57 | def visit_host(self, host): | ||
| 58 | self.hosts_visited.add(host) | 58 | self.hosts_visited.add(host) | ||
| 59 | 59 | ||||
| 60 | 60 | ||||
| 61 | class Host(Person): | 61 | class Host(Person): | ||
| 62 | 62 | ||||
| 63 | def __init__(self, position: tuple, candies: list): | 63 | def __init__(self, position: tuple, candies: list): | ||
| 64 | super().__init__(position) | 64 | super().__init__(position) | ||
| 65 | self.candies = [] | 65 | self.candies = [] | ||
| 66 | for candy_tuple in candies: | 66 | for candy_tuple in candies: | ||
| 67 | self.candies.append(Candy(candy_tuple[0], candy_tuple[1])) | 67 | self.candies.append(Candy(candy_tuple[0], candy_tuple[1])) | ||
| 68 | 68 | ||||
| 69 | def remove_candy(self, filter_func): | 69 | def remove_candy(self, filter_func): | ||
| 70 | if not self.candies: | 70 | if not self.candies: | ||
| 71 | return None | 71 | return None | ||
| 72 | 72 | ||||
| 73 | to_remove = filter_func(self.candies) | 73 | to_remove = filter_func(self.candies) | ||
| 74 | if to_remove is None: | 74 | if to_remove is None: | ||
| 75 | return None | 75 | return None | ||
| 76 | self.candies.remove(to_remove) | 76 | self.candies.remove(to_remove) | ||
| 77 | 77 | ||||
| 78 | return to_remove | 78 | return to_remove | ||
| 79 | 79 | ||||
| 80 | 80 | ||||
| 81 | class FluxCapacitor: | 81 | class FluxCapacitor: | ||
| 82 | 82 | ||||
| 83 | def __init__(self, participants: set): | 83 | def __init__(self, participants: set): | ||
| 84 | 84 | ||||
| 85 | self.kids = [] | 85 | self.kids = [] | ||
| 86 | self.hosts = [] | 86 | self.hosts = [] | ||
| 87 | person: Person | 87 | person: Person | ||
| 88 | for person in participants: | 88 | for person in participants: | ||
| 89 | if type(person) == Kid: | 89 | if type(person) == Kid: | ||
| 90 | self.kids.append(person) | 90 | self.kids.append(person) | ||
| 91 | else: | 91 | else: | ||
| 92 | self.hosts.append(person) | 92 | self.hosts.append(person) | ||
| 93 | 93 | ||||
| 94 | self.kids.sort(key=lambda x: x.initiative, reverse=True) | 94 | self.kids.sort(key=lambda x: x.initiative, reverse=True) | ||
| 95 | 95 | ||||
| 96 | def get_victim(self): | 96 | def get_victim(self): | ||
| 97 | victims = set() | 97 | victims = set() | ||
| 98 | 98 | ||||
| 99 | if len(self.kids) == 0: | 99 | if len(self.kids) == 0: | ||
| 100 | return None | 100 | return None | ||
| 101 | 101 | ||||
| 102 | loop = True | 102 | loop = True | ||
| 103 | 103 | ||||
| 104 | while loop: | 104 | while loop: | ||
| 105 | 105 | ||||
| 106 | kid: Kid | 106 | kid: Kid | ||
| 107 | for kid in self.kids: | 107 | for kid in self.kids: | ||
| 108 | closest_host = self._find_closest_host_to_kid(kid) | 108 | closest_host = self._find_closest_host_to_kid(kid) | ||
| 109 | if closest_host is None: | 109 | if closest_host is None: | ||
| 110 | loop = False | 110 | loop = False | ||
| 111 | break | 111 | break | ||
| 112 | 112 | ||||
| 113 | given = closest_host.remove_candy(self.get_biggest_candy) | 113 | given = closest_host.remove_candy(self.get_biggest_candy) | ||
| 114 | if given is not None: | 114 | if given is not None: | ||
| 115 | kid.add_candy(given) | 115 | kid.add_candy(given) | ||
| 116 | 116 | ||||
| 117 | if kid.is_critical(): | 117 | if kid.is_critical(): | ||
| 118 | victims.add(kid) | 118 | victims.add(kid) | ||
| 119 | loop = False | 119 | loop = False | ||
| 120 | 120 | ||||
| 121 | kid.visit_host(closest_host) | 121 | kid.visit_host(closest_host) | ||
| 122 | kid.set_position(closest_host.get_position()) | 122 | kid.set_position(closest_host.get_position()) | ||
| 123 | 123 | ||||
| 124 | 124 | ||||
| 125 | if victims: | 125 | if victims: | ||
| 126 | return victims | 126 | return victims | ||
| 127 | return None | 127 | return None | ||
| 128 | 128 | ||||
| 129 | def _find_closest_host_to_kid(self, kid: Kid): | 129 | def _find_closest_host_to_kid(self, kid: Kid): | ||
| 130 | current_closest_dist = -1 | 130 | current_closest_dist = -1 | ||
| 131 | closest_host = None | 131 | closest_host = None | ||
| 132 | 132 | ||||
| 133 | host: Host | 133 | host: Host | ||
| 134 | for host in self.hosts: | 134 | for host in self.hosts: | ||
| 135 | curr_dist = math.dist(kid.get_position(), host.get_position()) | 135 | curr_dist = math.dist(kid.get_position(), host.get_position()) | ||
| 136 | if host in kid.get_hosts_visited(): | 136 | if host in kid.get_hosts_visited(): | ||
| 137 | continue | 137 | continue | ||
| 138 | 138 | ||||
| 139 | if current_closest_dist < 0 or curr_dist < current_closest_dist: | 139 | if current_closest_dist < 0 or curr_dist < current_closest_dist: | ||
| 140 | closest_host = host | 140 | closest_host = host | ||
| 141 | current_closest_dist = curr_dist | 141 | current_closest_dist = curr_dist | ||
| 142 | elif curr_dist == current_closest_dist and host.get_position() < closest_host.get_position(): | 142 | elif curr_dist == current_closest_dist and host.get_position() < closest_host.get_position(): | ||
| 143 | closest_host = host | 143 | closest_host = host | ||
| 144 | current_closest_dist = curr_dist | 144 | current_closest_dist = curr_dist | ||
| 145 | 145 | ||||
| 146 | return closest_host | 146 | return closest_host | ||
| 147 | 147 | ||||
| 148 | def get_biggest_candy(self, host_basket: set): | 148 | def get_biggest_candy(self, host_basket: set): | ||
| 149 | biggest = None | 149 | biggest = None | ||
| 150 | 150 | ||||
| 151 | candy: Candy | 151 | candy: Candy | ||
| 152 | for candy in host_basket: | 152 | for candy in host_basket: | ||
| 153 | if biggest == None or biggest.get_mass() < candy.get_mass(): | 153 | if biggest == None or biggest.get_mass() < candy.get_mass(): | ||
| 154 | biggest = candy | 154 | biggest = candy | ||
| 155 | 155 | ||||
| 156 | return biggest | 156 | return biggest | ||
| 157 | 157 | ||||
| 158 | def get_kids(self): | 158 | def get_kids(self): | ||
| 159 | return self.kids | 159 | return self.kids | ||
| 160 | 160 | ||||
| 161 | 161 | ||||
| 162 | def get_biggest_candy(candies: list): | 162 | def get_biggest_candy(candies: list): | ||
| 163 | biggest = None | 163 | biggest = None | ||
| 164 | 164 | ||||
| 165 | candy: Candy | 165 | candy: Candy | ||
| 166 | for candy in candies: | 166 | for candy in candies: | ||
| 167 | if biggest == None or biggest.get_mass() < candy.get_mass(): | 167 | if biggest == None or biggest.get_mass() < candy.get_mass(): | ||
| 168 | biggest = candy | 168 | biggest = candy | ||
| 169 | 169 | ||||
| 170 | return biggest | 170 | return biggest | ||
| t | 171 | t | |||
| 172 | |||||
| 173 | kid1 = Kid((1, 2), 3) | ||||
| 174 | kid2 = Kid((3, 4), 2) | ||||
| 175 | host1 = Host((2, 2), [(5, 0.1), (100, 0.2)]) | ||||
| 176 | host2 = Host((4, 4), [(8, 0.3)]) | ||||
| 177 | flux_capacitor = FluxCapacitor(participants={kid1, kid2, host1, host2}) | ||||
| 178 | |||||
| 179 | victims = flux_capacitor.get_victim() | ||||
| 180 | #print(len(victims)) |
| Legends | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
| |||||||||
07.11.2023 09:11
07.11.2023 09:11
07.11.2023 09:12
07.11.2023 09:13
07.11.2023 09:13
07.11.2023 09:14
07.11.2023 09:15
07.11.2023 09:15
07.11.2023 09:15