Popular recipes tagged "combinatorics" but not "partition"http://code.activestate.com/recipes/tags/combinatorics-partition/2016-02-21T06:00:46-08:00ActiveState Code Recipespick all combinations of items in buckets (Python)
2015-09-05T07:39:42-07:00yotahttp://code.activestate.com/recipes/users/4184815/http://code.activestate.com/recipes/579098-pick-all-combinations-of-items-in-buckets/
<p style="color: grey">
Python
recipe 579098
by <a href="/recipes/users/4184815/">yota</a>
(<a href="/recipes/tags/combinatorics/">combinatorics</a>).
</p>
<p>Let be a number of buckets, containing each, a variable number of items. This function return all combinations possible of one item picked out of each bucket</p>
<p>example, with three buckets {ba, be, bi}, {ka, ko, ku, ke} and {to, ty}, the function enumerate as such: </p>
<pre class="prettyprint"><code> 0. ba-ka-to
1. ba-ka-ty
2. ba-ko-to
3. ba-ko-ty
4. ba-ku-to
5. ba-ku-ty
6. ba-ke-to
7. ba-ke-ty
8. be-ka-to
9. be-ka-ty
10. be-ko-to
11. be-ko-ty
12. be-ku-to
13. be-ku-ty
14. be-ke-to
15. be-ke-ty
16. bi-ka-to
17. bi-ka-ty
18. bi-ko-to
19. bi-ko-ty
20. bi-ku-to
21. bi-ku-ty
22. bi-ke-to
23. bi-ke-ty
</code></pre>
Get the inversion number of a permutation (Python)
2016-02-21T06:00:46-08:00Samuel James Ericksonhttp://code.activestate.com/recipes/users/4187478/http://code.activestate.com/recipes/579051-get-the-inversion-number-of-a-permutation/
<p style="color: grey">
Python
recipe 579051
by <a href="/recipes/users/4187478/">Samuel James Erickson</a>
(<a href="/recipes/tags/combinatorics/">combinatorics</a>, <a href="/recipes/tags/discrete/">discrete</a>, <a href="/recipes/tags/inversion/">inversion</a>, <a href="/recipes/tags/math/">math</a>, <a href="/recipes/tags/permutations/">permutations</a>).
Revision 2.
</p>
<p>This function takes a permutation in the form of a list and returns the number of inversions in the permutation. </p>
Permutation and combination using recursive generator (Python)
2011-10-04T05:44:19-07:00Shao-chuan Wanghttp://code.activestate.com/recipes/users/4168519/http://code.activestate.com/recipes/577890-permutation-and-combination-using-recursive-genera/
<p style="color: grey">
Python
recipe 577890
by <a href="/recipes/users/4168519/">Shao-chuan Wang</a>
(<a href="/recipes/tags/combinatorics/">combinatorics</a>, <a href="/recipes/tags/generators/">generators</a>, <a href="/recipes/tags/permutation/">permutation</a>, <a href="/recipes/tags/recursion/">recursion</a>).
Revision 2.
</p>
<p>This recipes demonstrates how to use recursive generator to implement permutation and combination.</p>