Category "prolog"

Finding intersection between two lists without duplicates in prolog

I am using Prolog and I am trying to find the intersection or the common elements between two lists and the result should not contain duplicates. In addition, t

Prolog: replace the nth item in the list with the first

I'd like to have a Prolog predicate that can replace the nth item in the list with the first. Example: % replace(+List,+Counter,-New List, %-First Item). ?- rep

No theory in Aleph SWI Prolog

My question is pretty similar to Not getting a theory in Aleph for SWI Prolog After trying to induce a theory, I end up getting only single atoms My code(only a

Prolog : Trying to get odd and even upto specific element of list

I want to know how many even and odd numbers are present in the list up to a specific index entered by the user. The following code is working but only gives ei

Prolog road crossing [closed]

How can I implement a solution to this problem in Prolog? There are 3 dogs and 3 cats on the West side of the road. If at any point there are

Reading and outputting from and to a file PROLOG

I have a programming assignment in one of my classes that is to implement a working binary search tree in Prolog along with a few traversals and other functions

Infinite recursion when trying to build a resolution solver in prolog in prolog

I am trying to build a resolution solver in prolog. My program works fine when I use primary connectives, but there is infinite recursion when I try to add seco

Output is a list of three elements [A,B,C] taken from items that together add up to goal. The Output inside the items list in that order

`three Sum([1,2,3,4,5,6,7,8,9],12,Output). Output=[1,2,9]; Output=[1,3,8]; Output=[1,4,7]; Output=[1,5,6]; Output=[2,3,7]; Output=[2,4,6]; Output=[3,4,5]

How to count the leaves of a tree in prolog?

I am trying to sum the leaves of a tree and cannot seem to do it correctly any help would be greatly appreciated. I have tried several different methods and non

Reverse the output of the Depth-First-Search Algorithm

I want to reverse the output of the code. goal(hall). move(gateA,gateB). move(gateA,gateG). move(gateB,gateC). move(gateB,gateH). move(gateG,gateL). move(gateG,

prolog filter/3 predicate never shows output

I want to create a predicate filter/3 or filter(Condition,List,Solution) that checks every element of the list and if returns true in the condition put it in th

How to generate a list with only two 1s and other 0s of the given length?

I have to generate lists that consist of 2 '1's and other elements are '0's. I tried the following code but it does not work: count([], _, 0). count([X|T], X,

Multiplication of all nodes in a binary tree

I'm trying to multiply all nodes in a binary tree but I'm only getting 0 as a result. My code is: product_tree(nil,0). product_tree(t(L,X,R), N):- product_tr

Prolog program that swaps the two halves of a list

I am new to this language and am having trouble coming up with a solution to this problem. The program must implement the following cases. Both variables are in

How can i set a newline in a set string in SWI-Prolog?

I have this string: B='Dogs cats birds and fish'. and i need it to appear in the format bellow: Dogs, cats, birds, and fish Is there any possible way for

Prolog power of 2 recursion

Need help creating a recursive clause is a rule: X is a power of 2 only if there is a Y such that when adding Y to Y the result is X, and Y is a power of 2. in

SWI-Prolog: Use operators from modules?

I have a prolog-file (name definitions.pl) of this kind of type: :- module(definitions,[]). :-op(699, xfx, :=). :-op(599, xfy, ∪). C := (A ∪ B) :- u

SWI-Prolog: How to retrieve confidence intervals for both input and output?

I have a knowledge base in SWI-Prolog that consists of rules with the form: input(a,c1,b,c2,c,c3):-output(good,c4). (c1,c2,c3,c4 represent the confidence values

Representing Infinite Domains in Prolog

How is it possible to represent infinite domains in Prolog? I have been searching this topic for a while, but do not have a clue. Any help is appreciated.

Finding shortest path of undirected weighted graph in prolog

I am trying to do a shortest path for a London underground system inside prolog, and I'm stuck I've managed to get the code to return lists of all the possible