To save codepoints, a compute-er can share 0
and -
, and share .
with $
(indicating a variable name).
A number matches RegEx /^-?(0|[1-9]\d*)(\.\d+)?$/
and a variable matches RegEx /^\$\d+$/
.
Given input where 0
and -
are represented as same char(your choice) and so do .
and $
, return as number or variable. You can assume that it's possible.
Test cases
0 => 0
10 => 10
01 => -1
00 => -0
001 => (undefined behavior)
1.3 => 1.3
.33 => $33
0.33 => 0.33
00.33 => -0.33
42.0 => 42.0
3.4.5 => (undefined behavior)
Shortest code wins.
42
a valid input? If so, add it add another testcase. \$\endgroup\$