Advertisement
Guest User

Untitled

a guest
Dec 4th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. gnome_sort(L1,L2) :-
  2. gnome_sort_intern(L1,[],L2).
  3.  
  4. gnome_sort_intern([],L,L).
  5. gnome_sort_intern([H|T],L1,L) :-
  6. insert(L1,H,L2),
  7. gnome_sort_intern(T,L2,L).
  8.  
  9. insert([],X,[X]).
  10. insert([H|T],X,[X,H|T]) :-
  11. X >= H,
  12. !.
  13. insert([H|T],X,[H|T2]) :-
  14. insert(T,X,T2).
  15.  
  16. czy_zerowy([]).
  17. czy_zerowy([H|T]):- H == 0, czy_zerowy(T).
  18. czy_minus1([H|T]):- H == -1 -> true; czy_minus1(T).
  19. dec(L, L, 0).
  20. dec([H|T], [HW|TW], I):- I > 0, HW is H-1, I2 is I-1, dec(T, TW, I2).
  21. pomniejsz([H|T], W):- dec(T, W, H) -> true; true.
  22.  
  23. czy_graf(C) :-
  24. (czy_zerowy(C) -> true;
  25. gnome_sort(C, C1),
  26. pomniejsz(C1, C2),
  27. not(czy_minus1(C2)),
  28. czy_graf(C2)).
  29.  
  30. czy_graficzny(Li, Odp):-
  31. (gnome_sort(Li, Li2),
  32. Li2=[H|_],
  33. length(Li, X),
  34. H < X,
  35. czy_graf(Li2) )-> Odp='Tak'; Odp='Nie'.
  36.  
  37. czy_spojny(Li,Odp) :-
  38. (
  39. czy_graficzny(Li,Odp),
  40. czy_zerowy(Li)
  41. ).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement