A collection of solutions to LeetCode challenges in OCaml.
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.
-
Automate this
-
Create a
.txtfile insidetestsnamed 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
===.
Writing tests for challenge 1 on LeetCode.
Create the file.
touch tests/1.txtAdd test cases.
2 7 11 15
9
===
0 1
---
3 2 4
6
===
1 2
---
3 3
6
===
0 1
- Create a(n)
.mlfile insidelib. - Add it as a module in the
solverslist defined inmain.ml.- The list entry should be in the form
("<challenge number>", module <Name>).
- The list entry should be in the form
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 theoutputto astring.val parse : string -> input: Provide a function to convert the test (read as astring) intoinput.val solve : intput -> output: Write the core algorithm.