~/problems / Simulation & OOP design / Object-oriented design and extensible simulations

OA: Task manager with quotas and history

medium 5 levels ~90 min Anthropic

Level 1 Tasks with generated ids

Build TaskManager. Every method takes an integer timestamp first; timestamps strictly increase from call to call.

  • add_task(timestamp, name, priority) -> str: create a task and return its id. Ids are handed out by a counter: the first task is "task_id_1", the next "task_id_2", and so on. Names don't have to be unique.
  • update_task(timestamp, task_id, name, priority) -> bool: replace the task's name and priority. False if there's no such task.
  • get_task(timestamp, task_id) -> str | None: the task as a compact JSON string with the name first and no spaces, exactly like {"name":"deploy","priority":3}. None for an unknown id.
tm = TaskManager()
tm.add_task(1, "deploy", 3)              # "task_id_1"
tm.add_task(2, "deploy", 7)              # "task_id_2"
tm.update_task(3, "task_id_1", "rollback", 9)   # True
tm.get_task(4, "task_id_1")              # '{"name":"rollback","priority":9}'
tm.update_task(5, "task_id_9", "x", 1)   # False

Names contain no quotes or backslashes. Priorities are integers and can be negative. The id format and the JSON layout are compared as exact strings.

Level 2 unlocks when level 1 passes.

Level 3 unlocks when level 2 passes.

Level 4 unlocks when level 3 passes.

Level 5 unlocks when level 4 passes.

Topic: Object-oriented design and extensible simulations. Classes that survive new requirements: games, payments, subscriptions, refactors.

0:00
Ctrl ' run · Ctrl ↵ submit
esc