In Prolog, problems are solved using backtracking. It\'s a declarative 开发者_JAVA技巧paradigm rather than an imperative one (like in C, PHP or Python). In this kind of languages is it worth to think
:- use_module(library(clpfd)). % load constraint library % [constraint] Compute a list of distinct odd numbers (if one exists), such that their sum is equal to a given number.
I have a question I would like to ask you something about a code snippet: insert_pq(State, [], [State]) :- !.
Q. Given [1,2,3] in Prolog get back [6,5,3] by reverse accumulation I have the start code: accumalate([H],[H]).
How to determine whether t开发者_开发问答wo list have same element in prolog? If i have two list A and B, i want to know whether they have the same element.You need to write a predicate. You\'ll proba
hi is there anybody know how cani do the pascal nth row when i开发者_如何学运维 ask for :? pascal(2,Row).
I have written a function for returning the next row in Pascal\'s triangle given the current row: pascal_next_row([X],[X]).
hill(+IntList) succeeds if IntList consists of monotonically increasing >integers followed by monotonically decreasing integers.For example, >[1,2,5,8,11,6,3,-1] is a hill, but [1,2,5,8,11,6,9,3,-1]
I know how to iterate over lists in Prolog to find the maximum, but what if each thing is a separate clause? For example if I had a bunch of felines and their ages, how would I find the oldest kitty?
I think the answer is 3 but I am not sure, can anyone provide some help? Suppose the following two statements are entered into Prolog: