1

This is my attempt so far. I am not sure what is wrong with this approach. Similar to other languages, the flatten equation

  1. Checks to see if the list is empty
  2. Checks to see if the head is empty, then continues with tail
  3. Checks is the head of original and unflattened list are equal
flatten([],[]).
flatten([X1|PS], [[X1|XS]) :- flatten(PS, [XS]).
flatten(PS, [X1|XS]) :- flatten(A, [X1]), flatten(B, [XS]), append(A,B, PS).
flatten( [PS],PS).
false
  • 10,264
  • 13
  • 101
  • 209
  • 1
    Please see [**Flatten a list in Prolog**](http://stackoverflow.com/questions/9059572/flatten-a-list-in-prolog), and think about whether this can ever be a true relation. I recommend you start with `append/2`, which is also what you typically need in practice. – mat Nov 20 '16 at 22:39
  • That one didn't work – HeroOfTales Nov 20 '16 at 22:47

0 Answers0