Your task is to take a list of arguments that are either integers or operators, and parse them like so:
There is a current operator, which starts as +.
Each time an operator is found, the current operator will change to it.
The possible operators are: "+", "-", "*", "/", and "%", which correspond to their meanings in C and most languages.
There is a running solution kept, which starts at 0.
Each time an integer is found, the solution is modified by the number depending on the operator; e.g. if the operator is "/" then the solution is divided by the number.
If an operation would result in a mixed number (i.e. with a decimal) then it must be floored back to an integer (i.e. the decimal must be chopped off).
Output the final solution.
For example:
The arguments 5 8 25 * 9 6 2 - 104 / 4 7 + 6 % 14
would result in:
5 8 25 * 9 6 2 - 104 / 4 7 + 6 % 14
0 5 13 38 342 2052 4104 4000 1000 142 148 8 -> 8
The inputs will be as command-line or function arguments, or an equivalent for your language.
Shortest code wins!
%
rounds towards -inf instead of 0? \$\endgroup\$