Category "prolog"

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

How to get the first, middle and last element of a list scheme and prolog?

I am trying to write a function in Scheme and Prolog that returns first, middle and last item of a list. E.g., find([4,5,8,7,9],L), L = [4,8,9]. I came up with

How to generate distinct solutions in Prolog for '8 out of 10 cats does countdown' numbers game solver?

I wrote a Prolog program to find all solutions to any '8 out of 10 cats does countdown' number sequence. I am happy with the result. However, the solutions are

Constraint Programming library or syntax issue in SWI-Prolog

I'm just trying to figure out constraint programming in SWI-Prolog, looking at this tutorial : http://en.wikibooks.org/wiki/Prolog/Constraint_Logic_Programming