Excel, 44 40 Bytes
=MOD(3-SIGN(1+LEN(A1)-2*FIND(",",A1)),3)
Finds the difference between Total Length + 1 and twice the position of the comma (Negative: Left; Zero: Tie; Positive: Right), use SIGN
to convert these into -1
, 0
and 1
. Then subtract this from 3 to give 4
/0
/2
, and take the Modulo Base 3 (1
, 0
, 2
)
Old version: 44 Bytes
=MID(102,2+SIGN(1+LEN(A1)-2*FIND(",",A1)),1)
Finds the difference between Total Length + 1 and twice the position of the comma (Negative: Left; Zero: Tie; Positive: Right), use SIGN
to convert these into -1
, 0
and 1
, add 2 (1
, 2
, 3
), and then use MID
to take the first, second or third digit from 102
, respectively.
(Using MID
saved 3 bytes over using CHOOSE
)
I also experimented with a more maths-based approach (Multiply the Sign by 1.5, round it in the Positive direction with CEILING
, then take the Absolute value), but that was 51 bytes instead.