Javascript ES6, 62 Bytes
s=>Math.sign([...s].reduce((p,c,i)=>p+~~c*(i-s.indexOf`^`),0)) -1if left is heavier0if balanced1if right is heavier
Ungolfed:
s=> Math.sign( // output sign of weight of lever [...s].reduce((p,c,i)=> // split and reduce input p+~~c*(i-s.indexOf`^`),0)) // add weights of all elements // (elements left of pivot are negatively weighted) Test runs (assigning anonymous function to f):
>> f("11 ^9") << 0 >> f("321^ 12") << -1 >> f("9^ 1") << 1 - -11 bytes: changed output from
R B Lto-1 0 1 - -3 bytes: changed
e.split``to[...e](thanks @Vɪʜᴀɴ) - -33 bytes: changed algorithm to use negative weights rather than splitting at pivot
- -9 bytes: removed pivot check (apparently,
~~'^'evaluates to0...) - -2 bytes: made function anonymous (thanks @cᴏɴᴏʀ-obʀɪᴇɴ)