From 94e6b904207ec79c811f8a1662c716e99e99fd64 Mon Sep 17 00:00:00 2001 From: Fatma Degirmenci Date: Mon, 16 Feb 2026 11:33:51 +0000 Subject: [PATCH] implement laptop allocation --- sprint5/laptop_allocation.py | 87 ++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 sprint5/laptop_allocation.py diff --git a/sprint5/laptop_allocation.py b/sprint5/laptop_allocation.py new file mode 100644 index 000000000..657eb58f4 --- /dev/null +++ b/sprint5/laptop_allocation.py @@ -0,0 +1,87 @@ +from dataclasses import dataclass +from enum import Enum +from typing import List,Dict,Tuple + + +class OperatingSystem(Enum): + MACOS = "macOS" + ARCH = "Arch Linux" + UBUNTU = "Ubuntu" + +@dataclass(frozen=True) +class Person: + name: str + age: int + preferred_operating_system: Tuple[OperatingSystem, ...] + + +@dataclass(frozen=True) +class Laptop: + id: int + manufacturer: str + model: str + screen_size_in_inches: float + operating_system: OperatingSystem + +# calculate sadness score +def calculate_sadness(person:Person,laptop:Laptop) -> int: + if laptop.operating_system in person.preferred_operating_system: + sadness=person.preferred_operating_system.index(laptop.operating_system) + return sadness + else: + return 100 + +def allocate_laptops(people: List[Person], laptops: List[Laptop]) -> Dict[Person, Laptop]: + if len(laptops) < len(people): + raise ValueError("Not enough laptops") + + total=float("inf") # store the min sadness + allocation:Dict[Person, Laptop]={} # store best allocation + + # try all possible laptop combinations + def find_best_allocation(person_index:int,current_total:int,current_allocation: Dict[Person, Laptop],remaining_laptops: List[Laptop]): + nonlocal total, allocation + if person_index == len(people): # everybody have a laptop + + if current_total {laptop.model} ({laptop.operating_system.value}) | sadness={s}") + + print("Total sadness:", total) +