Question
Write a tokenizer for a tiny arithmetic language. Given a source string, produce a list of [type, value] token pairs. Token types: 'NUM' for integer or decimal numbers (e.g. 12, 3.5), 'ID' for identifiers (letter or underscore followed by letters/digits/underscores), 'OP' for any single character in +-*/(), and 'WS' is skipped entirely. Any other character raises a ValueError. Numbers and identifiers are greedy (longest match). Return the list of [type, value] pairs in order.
tokenize(src: str) → list[list[str]]["x1 + 3.5 * (foo)"]out[["ID","x1"],["OP","+"],["NUM","3.5"],["OP","*"],["OP","("],["ID","foo"],["OP",")"]]State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.
Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.