title: Concating 2 lists with third list containing every different order of the elements of the 2 lists
body: <p>So I have 2 lists and when concatenated it should return a list like shown below</p>
  
  <p><strong>| ?- concat([a,b,c],[1,2,3,4],X).</strong></p>
  
  <p><strong>X = [a,b,c,1,2,3,4] ;</strong></p>
  
  <p><strong>X = [a,b,1,c,2,3,4] ;</strong></p>
  
  <p><strong>X = [a,b,1,2,c,3,4] ;</strong></p>
  
  <p><strong>X = [a,b,1,2,3,c,4] ;</strong></p>
  
  <p><strong>X = [a,b,1,2,3,4,c] ;</strong></p>
  
  <p><strong>...</strong></p>
  
  <p>So I wrote this code to answer the question:</p>
  
  <pre><code>concat([], Y, Y).
  concat([E|X], Y, [E|Z]) :- concat(X,Y,Z).
     concat(X, Y, [Y|X]).
  </code></pre>
  
  <p>But I get this as an output</p>
  
  <p><strong>?- concat([a,b,c],[1,2,3,4],X).</strong></p>
  
  <p><strong>X = [a, b, c, 1, 2, 3, 4] ;</strong></p>
  
  <p><strong>X = [a, b, c, [1, 2, 3, 4]] ;</strong></p>
  
  <p><strong>X = [a, b, [1, 2, 3, 4], c] ;</strong></p>
  
  <p><strong>X = [a, [1, 2, 3, 4], b, c] ;</strong></p>
  
  <p><strong>X = [[1, 2, 3, 4], a, b, c].</strong></p>
  
  <p>I'm new to Prolog so I'm not really sure where I'm going wrong, any help would be appreciated</p>