%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% ss(Xs, Ys) :-
% Ys is an =< ordered permutation of the list Xs
% Ys is derived from Xs by selection sort.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ss([], []).
ss([X|[]], [X|[]]).
ss(Xs, Ys) :-
% find the smallest in Xs
% remove the smallest from Xs
% sort the remaining of Xs after removing the smallest
% Put together the smallest in Xs with the sorted list of
% of the remaining in Xs together to get the result.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% removeFromToGet(L, Xs, Remaining_Xs) :-
%
% L is a member in the list Xs and removing L from Xs
% will ends in Remaining_Xs as the resulted list.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
removeFromToGet(L, [L| Tail_Xs ], Tail_Xs).
% if L is the head of Xs, removing it will give
% us the tail of Xs.
removeFromToGet(L, [X| Tail_Xs ], Remaining_Xs):-
% if L is not the head of Xs, removing L
% from the tail of Xs and then append the
% resulted list to [X] to get what we want.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% is_Smallest_In(L, Xs) :-
%
% L is the smallest value in Xs.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
is_Smallest_In(L, [L|[]]).
% For a list of 1 elelmernt, that element is the smallest.
is_Smallest_In(L, [L| Tail_Xs]) :-
% If L is smaller than the smallest in the tails of Xs,
% then L is the smallest in the whole list.
is_Smallest_In(Least_in_Tail_Xs, [L| Tail_Xs]) :-
% If L is no less than the smallest in the tails of Xs,
% the smallest in the tails of Xs is also
% the smallest in the whole list.