Skip to content

Instantly share code, notes, and snippets.

@Jell
Last active November 25, 2019 15:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jell/d938ada50ef0dc57a2a996b021bcc04e to your computer and use it in GitHub Desktop.
Save Jell/d938ada50ef0dc57a2a996b021bcc04e to your computer and use it in GitHub Desktop.

Programming Assignment

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

Executing

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment