Patience starting point
hand([[a,[[k,c],[5,d],[9,c],[3,c]]],[2,[[k,s],[4,d],[6,s],[6,c]]],
[3,[[t,h],[a,d],[4,c],[q,d]]],[4,[[2,h],[5,h],[3,s],[t,c]]],
[5,[[9,h],[4,h],[8,c],[5,c]]],[6,[[k,h],[2,c],[3,d],[a,c]]],
[7,[[3,h],[t,d],[8,h],[7,d]]],[8,[[2,d],[q,s],[h,s],[h,c]]],
[9,[[q,h],[2,s],[7,s],[k,d]]],[t,[[8,d],[j,d],[5,s],[6,h]]],
[j,[[8,s],[7,h],[9,s],[a,h]]],[q,[[q,c],[j,h],[4,s],[7,c]]],
[k,[[t,s],[9,d],[6,d],[a,s]]]]).
stack([],[],[]).
stack(Elem,[Elem|Stack],Stack).
pushstack(Rank,Elem,[[Rank,St1]|Rest],[[Rank,St2]|Rest]) :-
stack(Elem,St2,St1).
pushstack(Rank,Elem,[X|Rest1],[X|Rest2]) :-
pushstack(Rank,Elem,Rest1,Rest2).
popstack(Rank,Elem,[[Rank,St1]|Rest],[[Rank,St2]|Rest]) :-
stack(Elem,St1,St2).
popstack(Rank,Elem,[X|Rest1],[X|Rest2]) :-
popstack(Rank,Elem,Rest1,Rest2).
testpush(R,E,Y) :- hand(X),pushstack(R,E,X,Y).
testpop(R,E,Y) :- hand(X),popstack(R,E,X,Y).
Note - to push element e onto the stack you would call stack the
following way:
stack(e,S1,S2) -- passing in e and S2. This will put e onto S2 and return the new stack as S1.
To pop an element: stack(X,S1,S2) where S1 is the initial stack - X and S2 will be returned