Question
In Ocaml (* Implement the function few_divisors, which takes two * parameters n and m, and should return true if n has * fewer than
In Ocaml
(* Implement the function few_divisors, which takes two * parameters n and m, and should return true if n has * fewer than m divisors (including 1 and n), return * false otherwise. * * The few_divisors function should call the function * (bad_divisors n m) defined below if n <= 0 or m < 0. * * Some examples are as follows. few_divisors 17 3;; (* true -- 17 has only 1 and 17 *) few_divisors 4 3;; (* false -- 4 has 1, 4, and 2 *) few_divisors 4 4;; (* true -- 4 has only 1, 4, and 2 *) few_divisors 18 6;; (* false -- 18 has 1, 18, 2, 3, 6, and 9 *) few_divisors 18 7;; (* true -- 18 has only 1, 18, 2, 3, 6, and 9 *) *)
(* Don't remove these lines. Your code should replace undefined (). *) exception BadDivisors of int * int;; let bad_divisors n m = raise (BadDivisors (n,m));;
let rec few_divisors (n:int) (m:int) : bool = undefined () ;;
(* After the implementation, test your code with * following assertions. * * If your code passes all the following tests, it does NOT * mean that your implementation is COMPLETELY correct. You may figure out other test cases. *) assert (few_divisors 17 3);; assert (not (few_divisors 4 3));; assert (few_divisors 4 4);;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started