Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/oriches/xxx.interview.instructions

Interview question
https://github.com/oriches/xxx.interview.instructions

csharp functional interview-questions lazy-evaluation performance

Last synced: about 6 hours ago
JSON representation

Interview question

Awesome Lists containing this project

README

        

# XXX Interview Coding Test - Instructions

[![Build status](https://ci.appveyor.com/api/projects/status/k8mexsj23a615pkt?svg=true)](https://ci.appveyor.com/project/oriches/xxx-interview-instructions)

Built with ~~.NET 7.0.~~ .Net 8.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](https://github.com/oriches/Xxx.Interview.Instructions/blob/main/answer.png "Answer = 85ms")

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 - Evaluates the instruction at each label in and adds the result together
3) Mult - Evaluates the instruction at each label in and multiplies the results together

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.