Code Monkey home page Code Monkey logo

needle-count's Introduction

Needle count

Given a path to a file foo.txt, count how many times foo occurs in foo.txt.

The Haskell implementation is in hs/ and the FSharp implementation in fs/.

The code has been developed and tested on Linux.

The FSharp program has to be run using dotnet run either in Needle.CLI, or using the --project flag, e.g. dotnet run --project Needle.CLI/Needle.CLI.fsproj.

Caveats

  • The goal is that the code should lean more towards readability and simplicity rather than performance and complexity, e.g in the usage of advanced language features and extensions.
  • The F# version doesn't use libraries for things where it could be warranted (e.g. argument parsing). This is mostly due to lack of familiarity with the ecosystem.

Assumptions

  • If the program is given a path in another directory, e.g. foo/foo.txt, the term is assumed to be foo.txt, not foo/foo.txt.
  • If the program is given a file a.txt with contents aa, the expected count is 2.
  • If the program is given a file aa.txt with contents aaa, "overlapping" matches are not counted, i.e. the expected count is 1.
  • The user running the program has to have permissions to read the file.

Dev environment

The Haskell project uses cabal (specifically ghc version 9.4.8, but it'll likely work with other versions as well).

The FSharp project uses dotnet version 8.0.101.

For Nix users, shell.nix provides all the tools needed.

For instructions on how to install the required tools for non-Nix users, follow the tools' respective instructions at:

Tests

There are two types of tests:

  • unit tests
  • end-to-end (e2e) tests

Unit tests can be found in the respective project directories. E2E tests can be found in e2e-test.sh and the files needed are in the e2e-test dir.

N.B.: the e2e tests may not work on other platforms than Linux.

It should be possible to run the tests from the project directory, see Makefile.

needle-count's People

Contributors

eahlberg 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.