How do i add current and previous in Prolog? Beginner prolog

calcHeu([],K) :- nl.
calcHeu([X|Rest],K) :-
findMin(X,Y),write(Y),
calcHeu(Rest,Y).

if i pass [[1,2,3],[5,4,9],[7,8,9]] it will print 1 4 7 which is minimum of each list i want to add these value and return them. in a list or as single value.

Answers


I think this is what you want. Adding Y to a list everytime.

calcHeu([],K,List) :- nl.
calcHeu([X|Rest],K,[Y|Tail]) :-
findMin(X,Y),write(Y),
calcHeu(Rest,Y,Tail).

Do you really need the K variable? Doesn't seem to do much.


Need Your Help

Showing a hint for a C# winforms edit control

c# winforms user-interface

I'm working on a C# winforms application (VS.NET 2008, .NET 3.5 sp 1). I have a search field on a form, and rather than have a label next to the search field I'd like to show some grey text in the

Using Office to programmatically convert documents?

ms-office

I'm interested in using Office 2007 to convert between the pre-2007 binary formats (.doc, .xls, .ppt) and the new Office Open XML formats (.docx, .xlsx, .pptx)