New exercise: the Nonattacking Queens Problem.
This exercise uses the nondeterminism monad API, whose implementation has been the subject of several other exercises.
I have some problems with grading the last two questions (6-7). Grading works when learn-ocaml is executed in batch mode, with a timeout of 5 seconds. (I depend on the timeout mechanism to rule out a naïve solution to Question 7.) However, in the browser, I have several problems/questions:
-
How do I control the timeout value? I need to set it appropriately, so that a correct solution to Question 7 is accepted and a naïve solution is rejected.
-
How do I control the maximum stack size? The fact that tail recursion is not properly implemented causes even a correct solution to fail for very small values of
n. This is problematic, as I would like to try larger values ofn-- this is precisely how I can verify that the student's code is efficient.
Thank you, @fpottier!
I will push a patch to control timeout on a per-test basis.
About tail recursion, I will check that we use the more recent version of js_of_ocaml. The optimization of tail call in js_of_ocaml is (slowly but surely!) improving if I remember correctly.
A timeout value is hardly portable but I guess that you have no other way to control the amount of computational resources consumed by the program. To improve portability, you could simply multiply the timeout value with a well-chosen ratio when grading in the JavaScript environment.
I found no obvious way to know if you are grading in learn-ocaml-client or in the web app. A (somewhat hackish) way would be to inspect the environment like this:
let batch_mode () =
Sys.getenv_opt "SHELL" <> None