% Referencias:
%   http://ktiml.mff.cuni.cz/~bartak/prolog/sorting.html
%   https://www.csupomona.edu/~jrfisher/www/prolog_tutorial/2_7.html
%   http://200.17.141.213/~gutanunes/hp/IA/prolog_palazzo.pdf


%-------------------------
% PERMUTACAO

takeout(X,[X|R],R).
takeout(X,[F|R],[F|S]) :- takeout(X,R,S).

perm([X|Y],Z) :- perm(Y,W), takeout(X,Z,W).   
perm([],[]).


%-------------------------
% ORDENACAO INGENUA

naive_sort(List,Sorted) :- perm(List,Sorted), is_sorted(Sorted).
   
is_sorted([]).
is_sorted([_]).
is_sorted([X,Y|T]) :- X =< Y, is_sorted([Y|T]).
