Skip to content

Commit 1a6fb3b

Browse files
authored
Change allocation function to change the returning type of the function: Person and Laptop objects
Change allocation function to change the returning type of the function: Person and Laptop objects
1 parent 176ec47 commit 1a6fb3b

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

laptop-allocation.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ def calculate_sadness(person: Person, laptop: Laptop) -> int:
3737
return person.preferred_operating_system.index(laptop.operating_system)
3838
return 100
3939

40-
def allocate_laptops(people: List[Person], laptops: List[Laptop]) -> Dict[str, int]:
41-
best_allocation: Dict[str, int] = {}
40+
def allocate_laptops(people: List[Person], laptops: List[Laptop]) -> Dict[Person, Laptop]:
41+
best_allocation: Dict[Person, Laptop] = {}
4242
min_total_sadness = float("inf")
4343

44-
def backtrack(person_index: int, used_laptops: set, current_alloc: Dict[str, int], current_sadness: int):
44+
def backtrack(person_index: int, used_laptops: set, current_alloc: Dict[Person, Laptop], current_sadness: int):
4545
nonlocal best_allocation, min_total_sadness
4646

4747
# If all people assigned
@@ -62,7 +62,7 @@ def backtrack(person_index: int, used_laptops: set, current_alloc: Dict[str, int
6262
sadness = calculate_sadness(person, laptop)
6363

6464
used_laptops.add(laptop.id)
65-
current_alloc[person.name] = laptop.id
65+
current_alloc[person] = laptop
6666

6767
backtrack(
6868
person_index + 1,
@@ -73,7 +73,7 @@ def backtrack(person_index: int, used_laptops: set, current_alloc: Dict[str, int
7373

7474
# Undo choice
7575
used_laptops.remove(laptop.id)
76-
del current_alloc[person.name]
76+
del current_alloc[person]
7777

7878
backtrack(0, set(), {}, 0)
7979
return best_allocation

0 commit comments

Comments
 (0)