If I have a tree that for example looks like this: tree3(b(l(1),b(l(2),l(3)))). How would I write a program that counts the number of leaves?
I want to write a program that tells me if a tree is balanced or not. In this case balanced means same height or a height difference of 1.
The below predicate adds item X to list S.It works fine. addToSet(X, S, S) :- atomic(X), member(X, S), !.
Suppose I have a list [1,2,1,3,2,0,8,3,1],I wa开发者_运维问答nt to find the index of the last 3 which is 7, How to do it in prolog?Something like
Can someone help me with my file reading predicate? get_userinfo: write(\'\\nEnter Name:\'), readln(Name),
I get hat isa开发者_Python百科/2 is a rule, that takes two objects or terms. But what would isa2/2 imply? That isa is defined twice? isa2/2 simply refers to a predicate named isa2 taking 2 arguments,
This is my sample source code , I am using SWI Prolog , can someone tell me how to assert data that userkey in to txt.file. I want save the data in to txt.file.
Let\'s define custom operators - let it be ++,equals :- op(900, yfx, equals). :- op(800, xfy, ++). And fact:
GNU Emacs 23.2.1 prolog-mode-version is a variable defined in `prolog.el\'. Its value is \"1.22\" I have consulted the following file:
I am new to Prolog and was tasked with a Fibonnaci predicate fib( N, F) where N is the number in sequence, and F is the value.What I came up with does not work, but the solution I found seems identica