Code Monkey home page Code Monkey logo

adcenter-network-cc's Introduction

EIC Code Challenge - Haskell implementation
-----------------------------------------------

Haskell is a pure functional programming language, that allows to perform lazy evaluation for solving this problem.
Lazy evaluation is a method to evaluate a Haskell program. It means that expressions are not evaluated when they are bound to variables, but their evaluation is deferred until their results are needed by other computations. In consequence, arguments are not evaluated before they are passed to a function, but only when their values are used.
This means that input string will be read, and processed sequentially as it's needed, minimizing memory use.
* For the first challenge, string input is hardcoded. You can compile it with following command: ghc -O2 Challenge1.hs
* For the second challenge:
 * I used the "interact" function that reads input from STDIN and outputs to STDOUT the result of a function in real time.  You can compile it with following command: ghc -O2 Challenge2stdin.hs
 * I used file read/write functions that process both the input (input.txt) and output (output.txt) files in real time.  You can compile it with following command: ghc Challenge2file.hs
* There's also a unit test hs. You can compile it with following command: ghc -O2 Test.hs

For the Gene results, I'm returning a custom data defined as an array of 3-character tuple (codons), or an error. I'm using the default show method for printing results at this moment.

The string stream is passed to a function f that takes for parameters:
* Current codon, that is not completed until it has 3 elements
* Current gene (array of codons)
* Input string
* An incrementing index, meaning character position in the stream

And it returns an array of Result, being Genes and a possible error element at the end of the array (Once an error occurs, processing finishes).

function "f" reads characters from the string (ignoring white spaces, tabs, and comment lines) filling the current codon. Once the codon has 3 elements, we process it adding it to the end of the current gene, and in case it's a stop codon, we append the final gene to the result, and continue with a new empty gene (in case gene is a single noise stop codon, we don't append it to the result).

function "challenge" just calls function "f" with index=0 and empty codon and gene.

Downloading and Installing Haskell compiler (Windows)
------------------------------------------------

You can download GHC Installer here https://downloads.haskell.org/~ghc/7.4.2/ghc-7.4.2-i386-windows.exe (87 MB)

adcenter-network-cc's People

Contributors

juanmv94 avatar

Watchers

James Cloos avatar  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.