Reverse the output of the Depth-First-Search Algorithm

Advertisements 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],… Read More Reverse the output of the Depth-First-Search Algorithm

how do i flatten a complicate list in prolog?

Advertisements I have a list, which looks like -> [[[7, 8, 9], [7, 8, 9]]], I want to become follow example, [[[7,8,9],[7,8,9]]] -> [[7,8,9],[7,8,9]] is this possible? >Solution : It is possible: unpack([Ls], Ls). e.g. ?- unpack([[[7, 8, 9], [7, 8, 9]]], Answer). Answer = [[7, 8, 9], [7, 8, 9]]

How to "return" two values in prolog

Advertisements 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):-… Read More How to "return" two values in prolog