| summaryrefslogtreecommitdiff | 
diff options
Diffstat (limited to 'src/balancer/blc_distribution.erl')
| -rw-r--r-- | src/balancer/blc_distribution.erl | 59 | 
1 files changed, 59 insertions, 0 deletions
| diff --git a/src/balancer/blc_distribution.erl b/src/balancer/blc_distribution.erl new file mode 100644 index 0000000..2e8a141 --- /dev/null +++ b/src/balancer/blc_distribution.erl @@ -0,0 +1,59 @@ +-module(blc_distribution). + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +-export +( +   [ +      generate/2 +   ] +). +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +-spec generate_internals +   ( +      non_neg_integer(), +      list(list(0..100)), +      list(0..100) +   ) +   -> list(list(0..100)). +generate_internals (0, CurrentResult, _Sequence) -> +   CurrentResult; +generate_internals (N, CurrentResult, Sequence) -> +   generate_internals +   ( +      (N - 1), +      lists:filter +      ( +         fun (E) -> (lists:sum(E) =< 100) end, +         shr_lists_util:product +         ( +            fun (L, E) -> +               [E|L] +            end, +            CurrentResult, +            Sequence +         ) +      ), +      Sequence +   ). + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +-spec generate (non_neg_integer(), 0..100) -> list(list(0..100)). +generate (0, _Step) -> []; +generate (Elements, Step) -> +   Sequence = lists:seq(0, 100, Step), +   generate_internals +   ( +      (Elements - 1), +      lists:map(fun (E) -> [E] end, Sequence), +      Sequence +   ). | 


