I would like to calcul the distribution of a card hand in prolog. It means get this result:
?- distribution([sq,s9,s8,ha,hk,h5,da,dk,dj,d4,ca,c7,c6],D).
D=[[spade,3],[heart,3],[diamond,4],[club,3]]
But I don't know how to procede. I am able to get each color one by one, using this script:
distribution([], []).
distribution([H|T], [E|D]):-
atom_chars(H, X),
nth0(0, X, E),
(
E == 's' -> distribution(T, D);
E == 'h' -> distribution(T, D);
E == 'd' -> distribution(T, D);
E == 'c' -> distribution(T, D)
).
Can anyone help me? Thanks