Write a script/program that reads a sequence of mathematical expressions from a file and prints the result of evaluating all expressions in the order they appear.
The file consists of a series of expressions, one per line.
Each line is in the format function <value>
. ADD 5
, for example, adds 5 to the current value.
The initial value when the program starts is 0. A file contains maximum ten rows.
The following functions shall be supported:
ADD (addition, +)
SUB (subtraction, -)
MUL (multiplication, *)
DIV (division, /)
SQR (square, ^2) without value
Given the following example.file
:
ADD 5
ADD 7
SUB 9
SQR
Running:
./yourprogram example.file
should print "9".
We don't expect this task to be challenging. Rather, we are interested in your style. Feel free to pick any language you are comfortable with, although Go would be preferred.