Code Monkey home page Code Monkey logo

fsharpevaluator's Introduction

Problem

- Every instruction has a label specified by number followed by a colon e.g. "4:"
- There are 3 types of instruction:

  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)

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

My Notes

There are two ways I have included to compute the instructions

Option 1 (Recursive) Time Taken: 26.23 seconds

Option 2 Time Taken: 0.008 seconds

If this was production code I would all add some unit tests to this.

fsharpevaluator's People

Contributors

ltoshea avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.