oriches / Xxx.Interview.Instructions

Interview question

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

XXX Interview Coding Test - Instructions

Build status

Built with .NET 7.0.

What is this?

This is the solution to an interview coding test I wrote for a contract I never applied for - a friend & I were talking about it and I thought I'd give it ago!

Included below is a screenshot of my results followed by the instructions, but the major thing to note is I built this in .Net 5.0 .Net 7.0 not .Net 4.6.1 or less - so i guess I failed already :)

alt text

What the instructions doesn't tell you is to use the supplied input.txt data file and execute instruction 100:

Instructions

Your challenge is to write highly performant C# code that can correctly evaluate a list of instructions, the code should give the ability to be able to swap instruction format (label: instruction type items), should we wish to, for another unknown/undisclosed format along with the ability to support adding new or changing the supported instruction types.

- Every instruction in the supplied file has a label specified by number followed by a colon e.g. "4:"

- There are 3 instruction types in the supplied file:

  1) Value x         - Returns the value x
  2) Add <labels>    - Evaluates the instruction at each label in <labels> and adds the result together
  3) Mult <labels>   - Evaluates the instruction at each label in <labels> and multiplies the results together

  <labels> is a list of one or more numbers that refer to the label of other instructions in the input.

- The overall result for a set of instruction is the result of evaluating the first instruction.

For example, given the input:

0: Add 4 4 1
1: Mult 6 2
2: Value -3
3: Add 6 1 2
4: Value 5
6: Value 2

The first instruction is "Add 4 4 1", and the overall result is 4, which is produced as follows:

        Add 4 4 1
  ->    Add (5) (5) (Mult 6 2)
  ->    Add (5) (5) (Mult (2) (-3))
  ->    Add (5) (5) (-6)
  ->    Add (10) (-6)
  ->    (4)

Challenge: What is the overall result of evaluating the instructions in the input.txt file?

Further guidance: - As a rough guide, we expect you to spend around a couple of hours on this exercise. - Make sure to document any assumptions that you make. - Provide your answer, along with the code you have written and time the code takes to calculate the result. - The solution should be zipped up (excluding binaries) and all source returned, this must be able to build in VS2017/19 using .NET >= 4.6.1. - Your solution should log the time taken to evaluate each set of instructions, as well as the overall time to compute the full set of instructions. - Addtionally please document/implement the solution in such a way as to allow for extending the solution to support differing instructions sets.

About

Interview question

License:GNU General Public License v3.0


Languages

Language:C# 100.0%