You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the prep, there was an exercise around finding possible laptops for a group of people.
Your exercise is to extend this to actually allocate laptops to the people.
Given these class definitions:
fromdataclassesimportdataclassfromenumimportEnumfromtypingimportListclassOperatingSystem(Enum):
MACOS="macOS"ARCH="Arch Linux"UBUNTU="Ubuntu"@dataclass(frozen=True)classPerson:
name: strage: int# Sorted in order of preference, most preferred is first.preferred_operating_system: List[OperatingSystem]
@dataclass(frozen=True)classLaptop:
id: intmanufacturer: strmodel: strscreen_size_in_inches: floatoperating_system: OperatingSystem
Every person should be allocated exactly one laptop.
If we define "sadness" as the number of places down in someone's ranking the operating system the ended up with (i.e. if your preferences were [UBUNTU, ARCH, MACOS] and you were allocated a MACOS machine your sadness would be 2), we want to minimise the total sadness of all people. If we allocate someone a laptop with an operating system not in their preferred list, treat them as having a sadness of 100.
Maximum time in hours
3
How to submit
Submit a PR to this repo containing your function (and any supporting code).
Activity
AFatmaa commentedon Oct 27, 2025
CodeYourFuture/Module-Decomposition#58