/* selection/3 */
/*selection(E, R, L)*/
selection(X, Xs , [X|Xs]).
selection(E2  ,[X|R2]   , [X|Xs]):- selection(E2, R2, Xs).


compte([], Compte, [Compte|_]).
compte([TraceUnitaire|TraceSuite], Compte, L):-
    selectionDouble(GrandOperande, PetitOperande, Reste, L),
    calculer(TraceUnitaire, Resultat, GrandOperande, PetitOperande),
    compte(TraceSuite, Compte, [Resultat|Reste]).

selectionDouble(Grand, Petit, R, L):-selection(Grand, R1, L), selection(Petit, R, R1), Grand >= Petit.

calculer([Operande1 , '+', Operande2, '=', Resultat], Resultat, Operande1, Operande2):-
    Resultat is Operande1 + Operande2.
calculer([Operande1 , '*', Operande2, '=', Resultat], Resultat, Operande1, Operande2):-
    Resultat is Operande1 * Operande2.
calculer([Operande1 , '-', Operande2, '=', Resultat], Resultat, Operande1, Operande2):-
    Resultat is Operande1 - Operande2, Resultat \= 0.
calculer([Operande1 , '/', Operande2, '=', Resultat], Resultat, Operande1, Operande2):-
    Resultat is Operande1 / Operande2, integer(Resultat).

