Question

Prepare the following Prolog code. Create a min function that finds the minimum element in a list, i.e. min(X,L) is true when

0 0
Add a comment Improve this question Transcribed image text
Answer #1


min(M,[H|T]):- minlist(T,H,M).   %Accumulator Used and pick the 1st element as Minimum
minlist([],C,C):-!.   %If list becomes empty, instantiate Result with Accumulator
minlist([H|T],C,M):- C>=H,       %If Head of the list is Smaller than the current minimum
       M1 is H,   %Temporary Variable to store Minimum
       minlist(T,M1,M).   %Move ahead in search with the Current Minimum
minlist([_|T],C,M):- minlist(T,C,M).   %If not, continue with previous Minimum

/* Output Window */

Welcome to SWI-Prolog (threaded, 64 bits, version 8.0.2) SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software.

/* PLEASE UPVOTE */

Add a comment
Know the answer?
Add Answer to:
Prepare the following Prolog code. Create a min function that finds the minimum element in a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT