Skip to content

Instantly share code, notes, and snippets.

@ferd
Created July 16, 2013 13:39
Show Gist options
  • Save ferd/6008781 to your computer and use it in GitHub Desktop.
Save ferd/6008781 to your computer and use it in GitHub Desktop.
Calculate percentiles in the Erlang shell
f(Percentiles).
Percentiles = fun(Numbers) ->
Percentile = fun(List, Size, Perc) ->
Element = round(Perc * Size),
lists:nth(Element, List)
end,
Len = length(Numbers),
Sorted = lists:sort(Numbers),
[{trunc(Perc*100), Percentile(Sorted, Len, Perc)} ||
Perc <- [0.50, 0.75, 0.90, 0.95, 0.99, 0.999]]
end.
%% Percentiles([3, 7, 2, 6.25, ...]).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment