The prototype must be:
listMinPos(lst)
I’m able to write the same using two arguments, (list and index), but am not able to even think how it can be possible using only the list argument.
The following must hold:
- only 1 argument (the list).
- no external libraries.
- function should be recursive (no ‘let’ inside the function)
I have a solution that cheats slightly : I return the position of the smallest element, but not only. The value of the smallest element is also returned.
(As Pascal Cuoq noticed, there is still one
let p, v = .. in ..remaining; it can be replaced bymatch .. with p, v -> ... See comments).Another solution that relax your second constraint (no external library) :
It’s inefficient but I don’t think you can do much better without passing more information.
Edit
I didn’t understand this was a homework. Is there a policy against giving complete solution to homework questions ?
Anyway, in this case I suppose that the list of restriction you gave is not, as I supposed, a creativity-forcing constraint, and I suppose that you can break them if it gives better solutions.
I therefore propose, using local
let:And a tail-recursive version :