/ task_loader.py
task_loader.py
1 import json 2 import os 3 4 def load_all_tasks() -> tuple: 5 tasks = {"EASY": [], "MEDIUM": [], "HARD": []} 6 tests = {} 7 8 # Find tasks dir relative to this file, not cwd 9 base_dir = os.path.dirname(os.path.abspath(__file__)) 10 tasks_dir = os.path.join(base_dir, "tasks") 11 12 for task_folder in os.listdir(tasks_dir): 13 task_path = os.path.join(tasks_dir, task_folder) 14 if not os.path.isdir(task_path): 15 continue 16 with open(os.path.join(task_path, "task.json")) as f: 17 task = json.load(f) 18 with open(os.path.join(task_path, "tests.json")) as f: 19 test_data = json.load(f) 20 difficulty = task["difficulty"] 21 tasks[difficulty].append(task) 22 tests[task["id"]] = { 23 "baseline_time": task["baseline_time_ms"], 24 "baseline_mem": task["baseline_mem_mib"], 25 "cases": test_data["cases"] 26 } 27 return tasks, tests 28 29 TASKS, TESTS = load_all_tasks()