yuanqing / code-problems

:camel: Working through code problems in OCaml

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

code-problems Build Status

Working through code problems in OCaml.

Or, parlour tricks for the technical interview rigmarole.

Problems

All the problems are in src/, and loosely organised into categories below.

Each problem comprises a brief description, a solution program, and a test. (See Usage for instructions on how to build and run the tests.)

I. Data structures and algorithms

Array/list

Math

Queue

Sorting

Stack

Tree

II. Puzzles

Array/list

String

Other

Style guide

General practices

Naming conventions

Use short variable names if we are dealing with very few variables, or if the meaning is obvious (or can be intuitively inferred). Some general conventions:

  • Auxiliary function — aux
  • List — xs (or ys, zs)
  • Items in a list — x (or y, z)
  • List for accumulating values — acc
  • Binary tree — value v (or w) with a l subtree and a r subtree
  • String — str
  • Integer — n (or m)
  • Length of a string or list — len

If there is ambiguity (eg. when we are dealing with many variables of the same type), use more descriptive names in snake_case.

Usage

Pre-requisites

Set up

First, install ocamlfind, oUnit (for tests), and Bisect (for test coverage) with OPAM:

$ opam install ocamlfind ounit bisect

Then, grab this repository:

$ git clone https://github.com/yuanqing/code-problems

Run all the tests

$ cd code-problems/src
$ make

Use make coverage to run the tests and generate coverage reports (output to coverage/).

Run a particular test

…for example, for the binary search problem:

$ make binary_search/test

Use make binary_search/coverage to run the test and generate coverage reports (output to coverage/).

Clean

To remove all compiled files and other debris:

$ make clean

Known issues

  • The Bisect test coverage does not appear to be completely accurate.

Credit

The bulk of the problems are from the code-problems project maintained by Blake Embrey.

All solution programs in this repository were written by me.

License

MIT

About

:camel: Working through code problems in OCaml

License:MIT License


Languages

Language:OCaml 97.2%Language:Makefile 2.8%