|
1 | | -# from dataclasses import dataclass |
2 | | -# from enum import Enum |
3 | | -# from typing import List, Dict, Tuple |
4 | | - |
5 | | - |
6 | | -# class OperatingSystem(Enum): |
7 | | -# MACOS = "macOS" |
8 | | -# ARCH = "Arch Linux" |
9 | | -# UBUNTU = "Ubuntu" |
10 | | -# @dataclass(frozen=True) |
11 | | - |
12 | | -# class Person: |
13 | | -# name: str |
14 | | -# age: int |
15 | | -# preferred_operating_system: tuple[OperatingSystem, ...] |
16 | | - |
17 | | -# @dataclass(frozen=True) |
18 | | -# class Laptop: |
19 | | -# id: int |
20 | | -# manufacturer: str |
21 | | -# model: str |
22 | | -# screen_size_in_inches: float |
23 | | -# operating_system: OperatingSystem |
24 | | - |
25 | | -# def allocate_laptops(people: List[Person], laptops: List[Laptop]) -> Dict[Person, Laptop]: |
26 | | -# sadness_list: List[Tuple[int, Person, Laptop]] = [] |
27 | | -# for person in people: |
28 | | -# for laptop in laptops: |
29 | | -# if laptop.operating_system in person.preferred_operating_system: |
30 | | -# sadness = person.preferred_operating_system.index(laptop.operating_system) |
31 | | -# else: |
32 | | -# sadness = 100 |
33 | | -# sadness_list.append((sadness, person, laptop)) |
34 | | - |
35 | | -# sadness_list.sort(key=lambda x: x[0]) |
36 | | -# allocations: Dict[Person, Laptop] = {} |
37 | | -# allocated_laptops = set() |
38 | | - |
39 | | -# for sadness, person, laptop in sadness_list: |
40 | | -# if person not in allocations and laptop.id not in allocated_laptops: |
41 | | -# allocations[person] = laptop |
42 | | -# allocated_laptops.add(laptop.id) |
43 | | - |
44 | | -# return allocations |
45 | | - |
46 | | - |
47 | | - |
48 | | - |
49 | | - |
50 | | -# # sample |
51 | | -# people = [ |
52 | | -# Person("Imran", 22, (OperatingSystem.UBUNTU, OperatingSystem.ARCH, OperatingSystem.MACOS)), |
53 | | -# Person("Eliza", 34, (OperatingSystem.ARCH, OperatingSystem.UBUNTU)), |
54 | | -# ] |
55 | | -# laptops = [ |
56 | | -# Laptop(1, "Dell", "XPS 13", 13, OperatingSystem.ARCH), |
57 | | -# Laptop(2, "Apple", "MacBook", 13, OperatingSystem.MACOS), |
58 | | -# Laptop(3, "Dell", "XPS 15", 15, OperatingSystem.UBUNTU), |
59 | | -# ] |
60 | | -# allocations = allocate_laptops(people, laptops) |
61 | | -# for person, laptop in allocations.items(): |
62 | | -# print(f"{person.name} gets {laptop.manufacturer} {laptop.model} ({laptop.operating_system.value})") |
63 | | - |
64 | 1 | import sys |
65 | 2 | from dataclasses import dataclass |
66 | 3 | from enum import Enum |
|
0 commit comments