Skip to content

Commit 658bbdb

Browse files
committed
add if condition to find if we're at the best scenario leading to lowest sandess level
1 parent 9ffb839 commit 658bbdb

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

implement-laptop-allocation/main.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def sadness(person: Person, laptop: Laptop) ->int:
3636
def allocate_laptops(people: List[Person], laptops: List[Laptop]) -> Dict[Person, Laptop]:
3737

3838
best_scenario_assignment = None
39-
best_scenario_sadness = float("inf")
39+
best_total_sadness = float("inf")
4040

4141
for scenario in scenarios(laptops):
4242
total_sadness = 0
@@ -45,3 +45,9 @@ def allocate_laptops(people: List[Person], laptops: List[Laptop]) -> Dict[Person
4545
for person, laptop in zip(people, scenario):
4646
total_sadness += sadness(person, laptop)
4747

48+
#Check if this is the best scenario so far
49+
if total_sadness < best_total_sadness:
50+
best_total_sadness = total_sadness
51+
best_scenario_assignment = scenario
52+
53+

0 commit comments

Comments
 (0)