Rewrite eval to use the cursor. Read digit, advance, read op, advance, read digit, advance. The same four checks should still pass.
fn eval(input: []const u8) i64 {
source = input;
pos = 0;
const a: i64 = digit(cur());
pos += 1;
const op: u8 = cur();
pos += 1;
const b: i64 = digit(cur());
pos += 1;
return switch (op) {
'+' => a + b,
'-' => a - b,
'*' => a * b,
'/' => @divTrunc(a, b),
else => 0,
};
}
Same answers. But now we can move.