Skip to content

Commit abe33a9

Browse files
committed
wip:publish branch
1 parent 16ace89 commit abe33a9

2 files changed

Lines changed: 76 additions & 0 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.DS_Store
2+
**/.DS_Store
3+
.venv

laptop_alloctaion.py

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
from dataclasses import dataclass
2+
from enum import Enum
3+
from typing import List
4+
5+
6+
class OperatingSystem(Enum):
7+
MACOS = "macOS"
8+
ARCH = "Arch Linux"
9+
UBUNTU = "Ubuntu"
10+
11+
12+
@dataclass(frozen=True)
13+
class Person:
14+
name: str
15+
age: int
16+
# Sorted in order of preference, most preferred is first.
17+
preferred_operating_system: List[OperatingSystem]
18+
19+
20+
@dataclass(frozen=True)
21+
class Laptop:
22+
id: int
23+
manufacturer: str
24+
model: str
25+
screen_size_in_inches: float
26+
operating_system: OperatingSystem
27+
28+
29+
laptops = [
30+
Laptop(
31+
id=1,
32+
manufacturer="Dell",
33+
model="XPS",
34+
screen_size_in_inches=13,
35+
operating_system=OperatingSystem.ARCH,
36+
),
37+
Laptop(
38+
id=2,
39+
manufacturer="Dell",
40+
model="XPS",
41+
screen_size_in_inches=15,
42+
operating_system=OperatingSystem.UBUNTU,
43+
),
44+
Laptop(
45+
id=3,
46+
manufacturer="Dell",
47+
model="XPS",
48+
screen_size_in_inches=15,
49+
operating_system=OperatingSystem.UBUNTU,
50+
),
51+
Laptop(
52+
id=4,
53+
manufacturer="Apple",
54+
model="macBook",
55+
screen_size_in_inches=13,
56+
operating_system=OperatingSystem.MACOS,
57+
),
58+
]
59+
60+
61+
def allocate_laptops(
62+
people: List[Person], laptops: List[Laptop]
63+
) -> dict[Person, Laptop]:
64+
allocation = {}
65+
laptops_copy = laptops.copy()
66+
for person in people:
67+
for laptop in laptops_copy:
68+
for index in range(len(person.preferred_operating_system)):
69+
if laptop.operating_system == person.preferred_operating_system:
70+
allocation[person] = laptop
71+
# elif
72+
73+
return allocation

0 commit comments

Comments
 (0)