Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/theteachr/eleet_camel

Collection of solutions to LeetCode problems (in OCaml)
https://github.com/theteachr/eleet_camel

leetcode-solutions ocaml

Last synced: 4 days ago
JSON representation

Collection of solutions to LeetCode problems (in OCaml)

Awesome Lists containing this project

README

        

# Eleet Camel

A collection of solutions to LeetCode challenges in OCaml.

## Running

```
dune exec eleet_camel
```

runs all solutions against all test cases. In case of wrong solutions, you'll
see a diff in the `tests` directory.

## Adding Challenges

### Setting Up Tests

- [ ] Automate this

- Create a `.txt` file inside `tests` named after the challenge number on
LeetCode.
- Separate each test case by `\n---\n`.
- Add expected output for each test case, where the test and answer are
separated by `===`.

#### Example

Writing tests for challenge `1` on LeetCode.

Create the file.

```bash
touch tests/1.txt
```

Add test cases.

```
2 7 11 15
9
===
0 1

---

3 2 4
6
===
1 2

---

3 3
6
===
0 1
```

## Writing a Solution

### Registering an Implementation

- Create a(n) `.ml` file inside `lib`.
- Add it as a module in the `solvers` list defined in `main.ml`.
- The list entry should be in the form `("", module )`.

### Implementation

Make the `.ml` file created as part of _registration_ satisfy the following contract.

- `type input`: Specify the type of input to the main algorithm (`solve`).
- `type output`: Specify the type of output returned by the main algorithm
(`solve`).
- `val to_string : output -> string`: Provide a function to convert the
`output` to a `string`.
- `val parse : string -> input`: Provide a function to convert the test (read as
a `string`) into `input`.
- `val solve : intput -> output`: Write the core algorithm.