
Originally Posted by
Sanctus
I am giving
Erlang a look now out of curiosity.
Be prepared, it's a freaky language.
Code:
-module(listsort).
% Export 'by_length' with 1 parameter (don't care of the type and name)
-export([by_length/1]).
by_length(Lists) -> % Use 'qsort/2' and provides an anonymous function as a parameter
qsort(Lists, fun(A,B) -> A < B end).
qsort([], _)-> []; % If list is empty, return an empty list (ignore the second parameter)
qsort([Pivot|Rest], Smaller) ->
% Partition list with 'Smaller' elements in front of 'Pivot' and not-'Smaller' elements
% after 'Pivot' and sort the sublists.
qsort([X || X <- Rest, Smaller(X,Pivot)], Smaller)
++ [Pivot] ++ (╯°□°)╯︵ ┻━┻
qsort([Y || Y <- Rest, not(Smaller(Y, Pivot))], Smaller).
See, I understand nothing of what it says above. Apparently it's a quicksort algo. I edited it a bit to make it more... fun.
Bookmarks