# My algorithm produces too many permutations

Imagine the following problem. A population of size $n$ consists of $i$ men and $n-i$ women. The population goes to the casino. Call $g_m$ ,$g_w$ the amount of money won by men and women respectively. The event that men win $j$ dollars and women $k$ dollars occurs with probability $p_{jk}$. These probabilities are constant and the number of possible values of {$g_m$,$g_w$} is equal to $q$, finite. A visit to the casino constitutes then a multinational trial. Now I want to determine the distribution of money won by men and by women after $x$ casino visits.

My strategy was the following:

(1) I define a multinational distribution with

D = MultinomialDistribution[x, Pjk];


(2) There are $q$ pairs of {${g_m,g_w}$} for which the probability is higher than zero. I take each integers partition of the number of attempts $x$, (assume the integerspartition is of size $h$) add $q-h$ zeros so to obtain a vector of size $q$ and find all the permutations for this vector. This routine finds all the possible realizations of the $x$ visits.

P = IntegerPartitions[s];
For[k = 1, k < Length[P] + 1, k++,
Vec = Join[Vector, Permutations[Join[P[[k]], ConstantArray[0, j -Length[P[[k]]]]]]]];


(3) Let $G=${${g_m,g_w}$} be the vector of all possible outcomes after a casino visit. I define a function Visits that find the probability for the sum of gained money for men and women:

  Visits[C_]:=Module[{}, Join[Total[C*G], {PDF[D, C]}]];


(4) Finally, we gather all entries in the obtained distribution that represent the same outcomes by summing the respective probabilities

SumD = Flatten[{#[[1, {1, 2}]], Total[#[[All, 3]]]}] & /@
GatherBy[Map[Visits, Vec], #[[{1, 2}]] &];


Problem with this approach: When the size of $G$ is relatively high (around 80) and the number of visits $x>=4$, the size of the array of permutations exceeds $2^{31}$. Is there a way to get around this? Is it possible for example to write the permutations directly to a file instead of storing them in an array?

-
This is mathematically the same as your previous question. I strongly advise you to avoid using single capital letters as your variables. They can clash with built in definitions. And my previous advice applies. This is a problems where you would be better off rethinking the problem to avoid brute force permutations. –  Verbeia Jul 8 '13 at 13:44
"When the size of $G$ is relatively high (around 80)". How can $G$ be bigger than 2? –  m_goldberg Jul 8 '13 at 17:53
@m_goldberg: Thanks for the edition, the post looks much better now. I mean by the size of $G$ the number of possible outcomes of gained money by men and women and then by that the size of the probability array in the multinational distribution. –  Friedrich Nietzsche Jul 8 '13 at 18:20