Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- gnome_sort(L1,L2) :-
- gnome_sort_intern(L1,[],L2).
- gnome_sort_intern([],L,L).
- gnome_sort_intern([H|T],L1,L) :-
- insert(L1,H,L2),
- gnome_sort_intern(T,L2,L).
- insert([],X,[X]).
- insert([H|T],X,[X,H|T]) :-
- X >= H,
- !.
- insert([H|T],X,[H|T2]) :-
- insert(T,X,T2).
- czy_zerowy([]).
- czy_zerowy([H|T]):- H == 0, czy_zerowy(T).
- czy_minus1([H|T]):- H == -1 -> true; czy_minus1(T).
- dec(L, L, 0).
- dec([H|T], [HW|TW], I):- I > 0, HW is H-1, I2 is I-1, dec(T, TW, I2).
- pomniejsz([H|T], W):- dec(T, W, H) -> true; true.
- czy_graf(C) :-
- (czy_zerowy(C) -> true;
- gnome_sort(C, C1),
- pomniejsz(C1, C2),
- not(czy_minus1(C2)),
- czy_graf(C2)).
- czy_graficzny(Li, Odp):-
- (gnome_sort(Li, Li2),
- Li2=[H|_],
- length(Li, X),
- H < X,
- czy_graf(Li2) )-> Odp='Tak'; Odp='Nie'.
- czy_spojny(Li,Odp) :-
- (
- czy_graficzny(Li,Odp),
- czy_zerowy(Li)
- ).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement