CAPTCHA Modified by Evil Mathematician
I accidentally incurred the wrath of an eccentric passive-aggressive mathematician. As part of his demented idea of payback, he modified the CAPTCHA system on my favorite website. Up until now, it would just ask a moderately challenging math question, like
3+2^4, and I would simply type the answer,
19, to verify that I am a human being. But now, thanks to my mathematical nemesis, the CAPTCHA questions are obnoxiously hard to calculate by hand and it keeps me from logging into my profile!
From what I can tell, this is what he has done. The CAPTCHA images seem to still be the same, but the way it calculates the correct answer has changed. It takes the expression displayed in the image and rotates the operations. You wouldn't believe how long it took me to figure this out T__T.
Because of this fiasco, I need a program/function that takes in one of these expressions as a string, evaluates it and returns the result so that I can log onto my website! To make this a game, fewest bytes win.
Ok, you have the idea, lets walk through an example. Suppose that the CAPTCHA displayed an image with
6+5+4-3*2/1. Normally the answer would
9. Instead, we now have to rotate the operations to the right and that gives us
6/5+4+3-2*1. At this point, we evaluate it to be
Steps to evaluate the string input:
- Rotate the operation to the right
- Evaluate the result
- Full program or function
- Standard I/O
- Takes an expression
- Prints/Returns the evaluated result
- After the op rotation
- Possible operations are
- The negatives for negative numbers stays with the number when rotating
- Follow the normal order of operations after the rotation is completed
- Using integer division is allowed
- Possible numbers are positive/negative integers
- This does not include
- This does not include
- Parentheses could be included, but aren't rotated
Input -> Output 1+3 -> 4 7+6 -> 13 1+1-2 -> 2 3*4+2 -> 11 -7^4 -> -2401 3*7+1-3 -> -1 -9+4/4 -> 1.75 (4*1)+8 -> 40 1+2-3*4/5 -> -16.5 1+-2*3 -> 1 3*4--2 -> 11 30-2/7 -> 8 120*3-4+10-> 122 (13^-12)+11 -> 1
- [16-07-28] Fixed typo in last test case. I had posted the expression after rotating it once >___> , so that rotating a second time gave an incorrect answer. It is fixed now! Thanks to @sintax!
- [16-08-13] Removed broke test case. Thanks again to @sintax!