Skip to content

Commit 3cedf09

Browse files
Optimise: Prioritise users with fewer OS preferences to avoid high sadness scores and improve overall allocation quality
1 parent 76f824d commit 3cedf09

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

laptop_allocation/laptop_allocation.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,17 @@ def calculate_sadness(person:Person, laptop:Laptop)-> int:
9999
# ============================================================================
100100

101101
def allocate_laptops(people: List[Person], laptops: List[Laptop]) -> Dict[Person,Laptop]:
102+
102103
if len(laptops) < len(people):
103104
raise ValueError("Not enough laptops to allocate one per person")
105+
106+
107+
people_sorted = sorted(people, key = lambda p: len(p.preferred_operating_system))
104108

105109
result={}
106110
available_laptops = laptops.copy()
107111

108-
for person in people:
112+
for person in people_sorted:
109113
smallest_sadness = float("inf")
110114
best_laptop = None
111115

0 commit comments

Comments
 (0)