Skip to content

Commit f4bb681

Browse files
committed
define people and laptops data & write basic code to allocate laptops
1 parent 407b010 commit f4bb681

2 files changed

Lines changed: 51 additions & 0 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
node_modules
2+
implement-cowsay/.venv

laptop_allocation.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
from dataclasses import dataclass
2+
from enum import Enum
3+
from typing import Dict, List
4+
5+
class OperatingSystem(Enum):
6+
MACOS = "macOS"
7+
ARCH = "Arch Linux"
8+
UBUNTU = "Ubuntu"
9+
10+
@dataclass(frozen=True)
11+
class Person:
12+
name: str
13+
age: int
14+
# Sorted in order of preference, most preferred is first.
15+
preferred_operating_system: List[OperatingSystem]
16+
17+
18+
@dataclass(frozen=True)
19+
class Laptop:
20+
id: int
21+
manufacturer: str
22+
model: str
23+
screen_size_in_inches: float
24+
operating_system: OperatingSystem
25+
26+
laptops = [
27+
Laptop(id=1, manufacturer="Dell", model="XPS", screen_size_in_inches=13, operating_system="Arch Linux"),
28+
Laptop(id=2, manufacturer="Dell", model="XPS", screen_size_in_inches=15, operating_system="Ubuntu"),
29+
Laptop(id=3, manufacturer="Dell", model="XPS", screen_size_in_inches=15, operating_system="Ubuntu"),
30+
Laptop(id=4, manufacturer="Apple", model="macBook", screen_size_in_inches=13, operating_system="macOS"),
31+
]
32+
people = [
33+
Person(name="Imran", age=22, preferred_operating_system=["Arch Linux","Ubuntu"]),
34+
Person(name="Eliza", age=34, preferred_operating_system=["Arch Linux","macOS","Ubuntu"]),
35+
Person(name="Leila", age=45, preferred_operating_system=["macOS","Ubuntu","Arch Linux",]),
36+
Person(name="Mary", age=35, preferred_operating_system=["macOS","Arch Linux"]),
37+
]
38+
def allocate_laptops(people: List[Person], laptops: List[Laptop]) -> Dict[Person, Laptop]:
39+
for person in people :
40+
allocated=False
41+
for i in range(len(person.preferred_operating_system)) :
42+
for laptop in laptops :
43+
if person.preferred_operating_system[i] == laptop.operating_system :
44+
print(person.name,laptop.id,laptop.operating_system,i)
45+
laptops.remove(laptop)
46+
allocated=True
47+
break
48+
if allocated : break
49+
50+
allocate_laptops(people,laptops)

0 commit comments

Comments
 (0)