Q: Removing the first element from a list, and appending that element to another list in Prolog As the title states, I have four separate lists. What I want to be able to do is this:
/* Pseudo-code (not in prolog).. */
if(size(List1) % 2 == 1) {
    /* Take the head of List1, and move it to List2 */
}
if(size(List2) % 2 == 1) {
    /* Take the head of List2, and move it to List3 */
}
if(size(List4) % 2 == 1) {
    /* Take the head of List4 and move it to List2 */
}
if(size(List3) % 2 == 1) {
    /* Take the head of List3 and move it to List4 */
}

So, if I have this format: list(contents, list_name)
and the following facts:
list([1,2,3,4], List1).
list([5,6,7], List2).
list([8,9,10], List3).
list([11,12,13,14], List4).

% validList(ListNo,ListTransfer).
% If ListNo has an odd number of items, we can move any item to the list, ListTransfer).
validList(List1,List2).
validList(List2,List3).
validList(List2,List4).
validList(List4,List3).

I wrote this to check it, but I'm not sure I'm on the right path:
checkList(ListFrom,ListTo):-
    1 is mod(size(ListFrom), 2), % Check to see if size of list is odd
    ListFrom = [Head|Tail],      % it is, so we grab the head of the list
    append(Head, ListTo, ListTo).% we then append it to the correct list

I'm extremely new to prolog and am still trying to wrap my head around it. Is there a more concise way to code this shifting of a list item depending on certain constraints?

A: TL;DR: The two pseudo codes you give in the OP do not match!

The following is based on two assumptions:


*

*A fixed point is to be reached. After all, you wrote in one of your comments:

Basically, I know for a fact that at the end (after moving items around if there are an odd amount of items), that each list will have an even amount of items.


*The first pseudo code is what you are aiming for.

/* Pseudo-code (not in prolog).. */
if(size(List1) % 2 == 1) {
    /* Take the head of List1, and move it to List2 */
}
if(size(List2) % 2 == 1) {
    /* Take the head of List2, and move it to List3 */
}
if(size(List4) % 2 == 1) {
    /* Take the head of List4 and move it to List2 */

if(size(List3) % 2 == 1) {
    /* Take the head of List3 and move it to List4 */
}

Bad news: Above "code" may not reach a fixed point (that fulfills the first constraint)!
As a counterexample consider the following cycle (2->3->4->2):


*

*L1 = [], L2 = [2], L3 =  [], L4 =  []: Take the head of L2, and move it to L3

*L1 = [], L2 =  [], L3 = [2], L4 =  []: Take the head of L3 and move it to L4

*L1 = [], L2 =  [], L3 =  [], L4 = [2]: Take the head of L4 and move it to L2

*L1 = [], L2 = [2], L3 =  [], L4 =  []: go back to step 1
