Spreadsheet formula evaluator

Write codeHard45 minFigma and Stripe style

Your task

Evaluate a tiny spreadsheet. You are given a dict mapping cell names (e.g. 'A1') to formula strings. A formula is either a number (e.g. '5'), a cell reference (e.g. 'A2'), or a sum of operands joined by '+', where each operand is a number or a cell reference (e.g. 'A1+B2+3'). Resolve every cell to its integer value, following references. Return a dict mapping each cell name to its value. There are no cycles, and every referenced cell exists.

Examples

eval_spreadsheet(cells: dict[str,str]) -> dict[str,int]
Example 1
Inputeval_spreadsheet({"A1": "5", "A2": "A1+3", "A3": "A1+A2"})
Output{"A1": 5, "A2": 8, "A3": 13}