Basic primality test predicate in Prolog

I am trying to create a predicate isPrime/1 that checks if a given number is prime or not. I have come up with the following code: primeRec(_, 2). primeRec(X, Y) :- Y > 2, X mod Y-1 > 0, primeRec(X, Y-1). isPrime(2). isPrime(X) :- X > 1, X mod 2 > 0, primeRec(X, X). but… Read More Basic primality test predicate in 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,gateF). move(gateL,gateS). move(gateC,gateD). move(gateH,gateO). move(gateD,gateI). move(gateD,gateJ). move(gateI,gateP). move(gateP,gateQ). move(gateJ,gateR). move(gateR,hall). goSolveTheMaze( Start, Goal) :- depthfirst( [], Start, Goal). depthfirst( Path, Start, [Start | Path] ) :- goal( Start). depthfirst( Path,Start, Hall) :- move( Start, Node1), depthfirst( [Start | Path], Node1,… Read More Reverse the output of the Depth-First-Search Algorithm

How to "return" two values in prolog

I have two functions, first one calculates how many negative elements are in list, the second one forms list with indexes of negatives elements. I need to write a function called goal_negative_positions, that will "return" two values. My version don’t work, it always returns false. How to make it correct? negative_count([], 0):-!. negative_count([Head|Tail], Count):- Head… Read More How to "return" two values in prolog