Skip to content

Commit f8cec05

Browse files
Sort available laptops by ID and prioritize people with shorter preference lists in laptop allocation
1 parent c6d2222 commit f8cec05

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

implement-laptop-allocation/laptop_allocaton.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,10 @@ def allocate_laptops(people: List[Person], laptops: List[Laptop]) -> Dict[Person
113113
"""
114114
allocated_laptops : Dict[str, Laptop ]= {}
115115

116-
# create a shallow copy of the laptops list
117-
available_laptops = laptops[:]
118-
116+
# create a shallow copy of the laptops list sorted by id
117+
available_laptops = sorted(laptops, key=lambda l: l.id)
118+
119+
# sort people by length of their preferences first (avoids a score of 100 if possible)
119120
sorted_people = sorted(people, key=lambda p: len(p.preferred_operating_systems))
120121

121122
for person in sorted_people:

0 commit comments

Comments
 (0)