Created
February 14, 2011 07:03
-
-
Save d2fn/825578 to your computer and use it in GitHub Desktop.
partition set of numbers into subsets of equal size
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% produce a list, the elements of which are each lists of | |
% length 'Depth' of less forming sorted, equally sized bins | |
% of the numeric input list L | |
% the last bin will be of size (Depth rem length(L)) | |
equal_size_bins (L,Depth) -> | |
[tuple_to_list(X) || X <- equal_size_bins_sorted(lists:sort(L),Depth)]. | |
equal_size_bins_sorted (L,Depth) | |
when Depth >= length(L) | |
-> [list_to_tuple(L)]; | |
equal_size_bins_sorted (L,Depth) -> | |
{NextBin,Remaining} = lists:split(Depth,L), | |
[ list_to_tuple(NextBin) | equal_size_bins_sorted(Remaining,Depth)]. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment