I am trying to write a Prolog program that will print out the male successors of British Royalty in order. My attempt so far:
son(elizabeth, charles).
son(charles, william).
son(charles, henry).
son(elizabeth, andrew).
son(elizabeth, edward).
son(edward, severn).
successor(X, Y) :- son(X, Y).
successor(X, Y) :- son(X, C), successor(C, Y...
Hi guys,
I was wondering, how would I use the underscore twice but check that both instances of that underscore unify?
What I basically need is something that returns true if two elements of the same value in one mapping exist...
I.E member((,),[(a,a),(b,a),(c,a)]).
If I use a variable does that make them unified?
I.E ...
Hi,
I am trying to write a routing function but I cannot seem to get the result needed. This is the code so far.
Predecessor finds the node that is linked to N and returns it as P.
traceroute(_,L) :- member((A,A),L).
traceroute(N,L) :- predecessor(N,P),
append(N,L,L1),
traceroute(P,L1).
When I run my traceroute(placeA, Y). it retur...
How can I write a relation in prolog that determines if there are any two pairs in a list with the same sum. The relation should fail if there exist no pairs whose sums are equal. The relation should also fail if the list contains less than four elements.
list([1 2 3]) fails since it only has 3 elements
list([2 3 4 1]) succeeds since...
How to count how many times of a WORD occurs in a List?
For example:
counthowmany(hello,[hello,how,are,you,hello,hello],N).
N gives the total number of word 'hello' occurs
Thanks
...
Hi,
I am trying to perform a sum operation on every result of :
combination(0,_,[]).
combination(K,L,[X|Xs]) :- K > 0,
el(X,L,R), K1 is K-1, combination(K1,R,Xs).
el(X,[X|L],L).
el(X,[_|L],R) :- el(X,L,R).
For example, the user will enter is_sum_equal_10 ([1,2,3,4,5,6,7]) and the result will be true if the sum of any of the permut...
I'm trying to understand lists in prolog when I stumbpled over this problem:
there's a predicate mergeandmap/2 that should basically do this:
mergeandmap([[a1,...,an],...,[z1,...,zm]],[x1...xn])
%----------list 1------------ -list 2--
List 2 consits of letters (for example [a,b,c]).
List 1 consits of several lists with s...
Hey guys, a few simple prolog questions that I'm hoping you can help me on. Basically, I am trying to write a function that takes input as two lists, and an integer. From there, the function will try to find an x in the first list and a y in the second list such that x + y is equal to the input integer.
So far I am thinking to just rec...
not(A()) and not(D()) and not(B()) and not(A()).
What's the right way?
...
I'm wondering if there's an (understandable) way to brute force solve Post correspondence problem using prolog predicates?
for example:
?- pcp(["1","11"),("10111","101")], S).
S = [2,1,1]
...
not(A), not(D), not(B), not(not(D));not(not(A)), D, not(B), not(not(D));not(not(A)), not(D),B, not(not(D));not(not(A)), not
(D), not(B), not(D).
It reports :
ERROR: f:/program
files/pl/demo/test.pl:1:
No permission to modify static_procedure `(;)/2'
How to make it right?
...
im attempting to get my arms around some basic prolog but struggling a bit. in specific - im trying to got through a list of items and copy it, item by item into a new list. I can get it to reverse, but im finding it tricker doing it without reversing.
Ive been trying the following -
copy(L,R) :- accCp(L,R).
accCp([],R).
accCp([H|T],...
My goal for this Prolog function is as follows:
Given two lists, x and y, return true if y can be formed from x by reversing a contiguous part of list x.
For example, if the input is x = [1, 3, 2, 4], y = [1, 2, 3, 4], the result should be "true" because we can reverse the second and third elements of x to get y.
I really have no ide...
i'm counting number of instances in a list...
count(_,[],N,N).
count(Elem,[Elem|List],N,M) :- !, N1 is N+1, count(Elem,List,N1,M).
count(Elem,[_|List],N,M) :- count(Elem,List,N,M).
So, i wrote this up two ways in prolog, and the first one works (above), but i was curious to know why the second doesnt (or rather, will give me multip...
I need a relation in prolog to shift list left rotationally by one element such that
?shift([1,2,3],L) should produce
L=[2,3,1].
could you help me?
...
What kind of problems is better solved in Prolog than in Haskell? What are the main differences between these two languages?
ADDED: Is there a Haskell library (kind of a logical solver) that can mimic Prolog functionality?
...
Is there a way to "recursively redefine" (don't know the technical term) prolog predicates?
Consider these predicates:
f(X,Y,A):-A is Y xor X.
arity(f,2).
now i want to automatically create 2 new predicates f1/2 and f2/1 with the following definition:
f1(Y,A):-f(1,Y,A).
f2(A):-f1(1,A).
So the predicate should get a (binary) funct...
The criminal is one of A,B,C,D.
A says:Not me.
B says:It's D
C says:It's B
D says:Not me.
And we know that only one of them tells the truth.
Who is the one?I want to solve it by prolog.
It's an interview question.
...
Hi,
I've got this in a Prolog file:
:- module(test,[main/0, api_trial/2]
:- use_module(library(prologbeans)).
main:-
register_query(assert_trial(Age,Res), api_trial(Age,Res)),
start.
person('John',10,'London').
person('Adam',10,'Manchester').
api_trial(Age,Res) :-
findall((P,Age,Add),person(P,Age,Add),Res).
In Java, I do t...
Is there a way to test wether an arbitrary list is symmetric?
For example:
?- symmetric([a,b,b,a]).
true.
?- symmetric([a,b,c,a]).
false.
?- symmetric([a,a]).
true.
My attemp was to compare the first element to the last element and if they are equal to remove them and proceed with the rest of the list; otherwise fail. Succeed if th...