Another Excel set_cell and get_cell problem. It starts out really simple and then ramps up step by step, and time was still really tight while writing it.
Scope 1
Implement a simple Excel. You need
set_cell(label: str, value: int)
and
get_cell(label: str) -> int | None
In step one, set only takes numbers, no formulas, so I'd suggest getting through it fast and not wasting time.
Scope 2
Step two adds the ability to set a formula, e.g. set_cell("A1", "=B1+C1+1") or set_cell("A1", "=1+2"). Also, if a cell has never been set, get_cell needs to return None or an Error (make sure you handle this case). This step still doesn't need to consider cycle references like A1 -> B1 -> A1. You also don't need to worry much about optimizing dependency updates. I'd suggest recomputing every previously set cell inside set_cell, which guarantees get_cell is O(1).
Scope 3 (follow-up)
Add cycle detection, plus possible optimizations (recompute only the cells that have deps).
Honestly, it's still quite a lot of code. Watch your time while writing, and try to make sure each scope actually runs as you finish it. Don't try to do everything in one go.
Discussion
Loading comments…