prolog recurrence problem

1

How to solve this? I'm trying to make a program that gets a path and translates in the following directions (up (0), right (90), left (270), down (180)). The predicate vizinha of the Dir one of the directions (0,90,180,270), example: test([ (5, 5), (5, 6), (6, 6), (6, 7), (7, 7)],L). should give L=[0,90,0,90] , but L=[0] . I made trace and this is the link of the image The trace

test([(_,_)],_).

test([A|P],List):-
    B=(_,_),
    append([B],_,P),     
    vizinha(A,B,Dir), 
    append(List,[Dir],List1), 
    test(P,List1).
    
asked by anonymous 08.11.2016 / 00:48

1 answer

1

Your second append has arguments in the wrong order. Recall that the output value of test is List , then List is that it has to start with Dir and end with the result of recursion:

append([Dir], List1, List),

In addition, your base case is returning "anything" if the entry has only one element - ideally it would return the empty list, otherwise there will be infinite results:

test([(_,_)], []).

Example on ideone

    
26.12.2016 / 11:01