1
votes

Here is my code:

getMin([Y|List1],X):-
    getMin(List, Y, X).

getMin([A|List],B,X):-
        A=<B,
        getMin(List,A,X);
        B=<A,
        getMin(List,B,X).
getMin([],X,X).

When entering getMin/3 A is supposed to be 1 as I understand, but at A=< B I get "Arguments are not sufficiently instantiated" error. Why and how to fix it?

I also found this but since I'm very new to Prolog, I don't realize where exactly they got the error there and why the argument where not instantiated there. (There are lot's of other similar posts but it is hard to make the connection between other a bit different programs and yours.)

1
Similar to your other question, try to make the ; better visible by indentation. Also note, that you get 2 answers for getMin([1,1],X) which is not incorrect, but inefficient. - false

1 Answers

1
votes

There is a typo in first rule head: List1 instead of List. If you would use SWI-Prolog, its syntax highlight facility would help you to spot such problems.

edit here you can see what i mean the image with List1 and List highlighted

test, after the correction:

?- getMin([4,2,6,1,3],X).
X = 1 ;
false.