Created
July 3, 2022 16:14
-
-
Save nevikw39/081cb6deb7860805fd39edb59a220c95 to your computer and use it in GitHub Desktop.
Perform a `match` based on the measure adopted by the Div. of Curriculum, NTHU to assign the students to GE & PE courses.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
from typing import List | |
class Member: | |
def __init__(self, s: str, lst: List[int]) -> None: | |
self.s = s | |
self.lst = lst | |
self.n = 0 | |
class Task: | |
def __init__(self, s: str, n: int) -> None: | |
self.s = s | |
self.lst = [] | |
self.n = n | |
def match(n: int, m: int, members: List[Member], task_s: List[str], task_n: List[int]) -> List[Task]: | |
''' | |
This `match` function is based on the measure adopted by the Div. of Curriculum, NTHU to assign the students to GE & PE courses. | |
n: # lst of a member | |
m: the max # task of a memeber | |
https://curricul.site.nthu.edu.tw/p/404-1208-171788.php | |
''' | |
tasks = [Task(s, n) for s, n in zip(task_s, task_n)] | |
for i in range(n): # 1. | |
for j, task in enumerate(tasks): # 2. | |
if len(task.lst) >= task.n: # 3. | |
continue | |
for k in range(m): # 5. | |
# 4, 6. | |
candidates = list(filter( | |
lambda x: i < len(x.lst) and x.lst[i] == j and x.n == k, | |
members | |
)) | |
for member in random.sample(candidates, min(task.n - len(task.lst), len(candidates))): # 7, 9. | |
member.n += 1 | |
task.lst.append(member.s) | |
return tasks | |
def main(): | |
members = [] | |
for _ in range(6): | |
members.append(Member(input(), list(map(int, input().split())))) | |
for i in match(3, 1, members, ["QE", "Dask", "DL_DNA"], [2] * 3): | |
print(i.s, i.lst) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment