Learn OCaml by solving coding challenges from LeetCode, Edabit, and similar sites.
- Install OCaml and opam.
- Install dependencies:
opam install dune alcotest ocamlformat - Clone this repository.
- Run
./new-challenge.shto create a new challenge stub (see below). - Implement the solution in the generated
solution.mlfile. - Run
dune testto verify your solution. - Continue to the next challenge.
Use the new-challenge.sh script to create a properly structured challenge directory:
$ ./new-challenge.sh
==> Creating a new OCaml challenge stub
Challenge name: Remainder of Two Numbers
Description (one line, optional):
Two numbers are passed as parameters. The first parameter divided by the second parameter will have a remainder, possibly zero. Return that value.
Function signature (e.g., 'addition a b : int' or 'convert minutes'):
remainder a b : int
Enter test cases. For each, provide arguments separated by spaces, then '->', then expected value.
Examples:
Single arg: 5 -> 1825
Two args: 2 3 -> 5
String: "hello" -> "HELLO"
Finish with an empty line.
7 2 -> 1
3 4 -> 3
(-9) 45 -> (-9)
5 5 -> 0
==> Creating ./challenges/0004-remainder-of-two-numbers
==> Done. Created ./challenges/0004-remainder-of-two-numbers
==> Next steps:
1. Edit ./challenges/0004-remainder-of-two-numbers/solution.ml to implement remainder
2. Run 'dune test --action-stdout-on-success=swallow' from project root