CAPTCHA Modified by Evil Mathematician
Python 3.5, 118 113 164 bytes:
from re import*
def R(U):Z='(?<!\d)-\d+|\d+|[()]';O=sub(Z,'',U);print(eval(sub(Z,'%s',U).translate(str.maketrans(O,O[::-1])).replace('^','**')%tuple(findall(Z,U))))
A named function. Can probably be golfed down more. This will take quite a while and apparently plenty of memory to compute the solution for the input:
((22^22)+2*2^2^2^2*2-2+222222+22222*-2222-2*222*2*2+2^-2+(2+2+2+2+2)+222/222+2+22*2*2)*2*2*2
I started processing this with my program about 30 minutes ago as of the time of this edit (9:52 PM on July 27, 2016) and it is still going. EDIT: Well, it eventually started to take up too much memory, so I had to stop it at around 1 hour after I started, at around 10:52 PM on July 7, 2016.
EDIT # 2: Well, even for the updated last test case it's pretty much the same thing, as it takes quite a while for my program to start finding the answer before it eventually quits out on me with error code 137.
Try It Online for the Rest of the Test Cases! (Ideone)
Python 3, 195 bytes:
import re;I=input();x=[i for i in I if i in'+-*/^'];print(eval(''.join([i[0]+i[1]for i in[i for i in map(list,zip(*[[i for i in re.split('[+*/^-]',I)],x[-1:]+x[:-1]+['']]))]]).replace('^','**')))
Takes input on STDIN and leaves a number on STDOUT. I know that R. Kap already posted a Python answer, but the method I used is actually pretty interesting, so I thought I'll post this anyway.
The program first makes an the list: [chunks splitted by math chars, math chars rotated to the right]
. It then transposes the array, flattens, converts to string, and evaluates.
Dyalog APL, 30, but soon to be 16 bytes
⍎w⊣((w∊f)/w)←¯1⌽w∩f←'+-×÷'⊣w←⍞
Ungolfed, explained version:
w ← ⍞
Prompt for input (of the expression) and assign to w
f ← '+-×÷'
assign the symbols to f
((w ∊ f) / w) ← ¯1 ⌽ w ∩ f
using membership of f as mask, reassign those positions in w to the corresponding character in the cyclic 1-step-right rotated intersection of w and f (the symbols)
⍎w
execute the modified expression
There is no special handling of minus/negative, because APL uses the distinct symbols -
and ¯
.
See the rotation of symbols on TryAPL!
In version 16 it will be much shorter as a function which takes the expression as argument:
⍎¯1∘⌽@(∊∘'+-×÷')
Execute ⍎
the negative one step rotation ¯1∘⌽
done on @
members of the symbols set (∊∘'+-×÷')
.