title: Swapping a specific number in list 1 with a specific number in list 2
body: <p>I have been brushing up on some Prolog recently. I kind of enjoy just coming up with random problems to try and solve and then working them out. This one is quite tough though, and I'm not one to give up on a problem that I have set out to solve.</p>
  
  <p><strong>The problem:</strong> I want to make a predicate that will have 2 predetermined lists, 2 numbers to swap, and then output the lists after the swapping is done.</p>
  
  <p><strong>Further Explanation:</strong> I made it a little harder on myself by wanting to find a specific unique number from list 1, and swapping this with a specific unique number from list 2 so that if I have 2 lists...
  [7,2,7,8,5], and [1,2,3,8,7,9,8], and then give the predicate 2 numbers(Lets just say 8 and 7), then the number 8 and the number 7 will be swapped between the lists <strong>IF AND ONLY IF</strong> the number 8 is in the first list and the number 7 is in the second list. (It would disregard an 8 in the second list and a 7 in the first list). </p>
  
  <p>Sample query with expected answer:</p>
  
  <pre><code>?- bothSwap([7,2,7,8,5],[1,2,3,8,7,9,8],8,7,X,Y).
  X = [7,2,7,7,5], Y = [1,2,3,8,8,9,8].
  </code></pre>
  
  <p>I kind of got stuck at this point: </p>
  
  <pre><code>bothSwap([],L2,N1,N2,[],L2).
  bothSwap(L1,[],N1,N2,L1,[]).
  bothSwap([H1|T1],[H2|T2],N1,N2,X,Y) :- H1 == N1, H2 == N2, bothSwap(T1,T2,N1,N2,D1,D2), append(D1,[H2],X), append(D2,[H1],Y).
  bothSwap([H1|T1],[H2|T2],N1,N2,X,Y) :- H1 == N1, H2 =\= N2, bothSwap([H1|T1],T2,N1,N2,D1,D2).
  bothSwap([H1|T1],[H2|T2],N1,N2,X,Y) :- H1 =\= N1, H2 == N2, bothSwap(T1,[H2|T2],N1,N2,D1,D2).
  </code></pre>
  
  <p>Any bright minds out there willing to tackle this problem with me? :)</p>