I'm new to OCaml. I have a little exercise for training to get familiar with the notion of mutual recursion in OCaml. The idea of the function I need to write is to be able to count the steps of the function Basically : there's a warehouse with 2 employees who need to get those boxes out. Employee A can take out one box at a time, Employee B can take out 2 boxes at a time if the number of remaining boxes is even. Taking out one box (or two) is one step.
I've tried to use a variable that I try to increment each time one of the function is called.
Here's the code I have so far.
let rec employeeA n =
let x = 0 in
if n > 0 && n mod 2 = 0 then
x + 1 + employeeB(n-2)
else
0
and employeeB n =
let x = 0 in
if n > 0 && n mod 2 != 0 then
x + 1 + employeeA(n-1)
else
0;;
So far it kept returning 0 or 1 for employeeA function or 0 or 2 for employeeB function. Although the expected result would be that for 11 boxes for example, if EmployeeA starts, it should return 10 steps, and if EmployeeB starts, 11 steps.
Thanks.