fard(X):-A is X mod 2,A=1.
chapFard([]).
chapFard([N|L]):-fard(N),write(N),write(' '),chapFard(L),!.
chapFard([_|L]):-chapFard(L).

%---------------------------------
delFirst([],[]).
delFirst([_|L],L).

delLast([],[]).
delLast([_],[]).
delLast([A|L],[A|T]):-delLast(L,T).


delFirstX([X|L],X,L):-!.
delFirstX([A|L],X,[A|T]):-delFirstX(L,X,T).

delLastX([],_,[]).
delLastX([X|L],X,L):-not(member(X,L)),!.
delLastX([A|L],X,[A|T]):-delLastX(L,X,T).

delLastX2(L,X,T):-reverse(L,R),delFirstX(R,X,Q),reverse(Q,T).

%-----------------------------------
reverse(L,R):-rev(L,[],R).
rev([],R,R).
rev([H|T],L,R):-rev(T,[H|L],R).

%-----------------------------------
delXN([X|T],X,1,T).
delXN([X|L],X,N,[X|T]):-New is N-1,delXN(L,X,New,T).
delXN([A|L],X,N,[A|T]):-delXN(L,X,N,T).
%-----------------------------------
delX([],_,[]).
delX([X|L],X,T):-delX(L,X,T).
delX([A|L],X,[A|T]):-delX(L,X,T).
%-----------------------------------
jayGashtX(L,X,J):-delFirstX(J,X,L).

%-----------------------------------
appendFirst([],L,L).
appendFirst([X|T],L,[X|Q]):-appendFirst(T,L,Q).
appendLast(A,B,L):-appendFirst(B,A,L).
appendL(L,[],L).
appendL(L,[X|T],[X|Q]):-appendL(L,T,Q).
suffix(L,S):-appendFirst(S,_,L).
prefix(L,P):-appendL(P,_,L).
%-----------------------------------
minList([M],M).
minList([H|T],M):-minList(T,M),M=<H.
minList([H|T],H):-minList(T,M),H<M.
maxList([M],M).
maxList([H|T],M):-maxList(T,M),M>=H.
maxList([H|T],H):-maxList(T,M),H>M.
%-----------------------------------
selectionSort(L,S):-selSort(L,[],S).
selSort([],S,S).
selSort(L,T,S):-maxList(L,M),delFirstX(L,M,Ln),selSort(Ln,[M|T],S).

