Created
May 28, 2018 21:15
-
-
Save benjaminaaron/65c7ceecea806331e3687dec0e7ed560 to your computer and use it in GitHub Desktop.
possible subgroup constellations in a group of size n
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
import java.util.ArrayList; | |
import java.util.Arrays; | |
import java.util.List; | |
import java.util.stream.Collectors; | |
public class Main { | |
static List<List<Integer>> partitions = new ArrayList<>(); | |
static void partition(int n, int max, String prefix) { | |
// from https://introcs.cs.princeton.edu/java/23recursion/Partition.java | |
if (n == 0) { | |
partitions.add(Arrays.stream(prefix.trim().split(" ")).map(Integer::valueOf).collect(Collectors.toList())); | |
return; | |
} | |
for (int i = Math.min(max, n); i >= 1; i--) { | |
partition(n-i, i, prefix + " " + i); | |
} | |
} | |
static long faculty(int val) { | |
long faculty = 1; | |
for (int i = 1; i <= val; i ++) { | |
faculty *= i; | |
} | |
return faculty; | |
} | |
static long binomialCoefficient(int n, int k) { // n over k | |
return faculty(n) / (faculty(k) * faculty(n - k)); | |
} | |
public static void main(String[] args) { | |
int n = 13; // group of size n | |
boolean oneMemberPerSubgroup = true; // false means a group member can be in multiple subgroups | |
partition(n, n, ""); | |
System.out.println(partitions.size() + " subgroup constellations are possible with a group of " + n + ":"); | |
System.out.println(partitions); | |
long summedOptions = 0; | |
for (List<Integer> row : partitions) { | |
long options = 1; | |
int n_left = n; | |
for (Integer groupSize : row) { | |
long binom = binomialCoefficient(n_left, groupSize); | |
options *= binom; | |
if (oneMemberPerSubgroup) { | |
n_left -= groupSize; | |
} | |
} | |
System.out.println(options + " ways to arrange " + n + " in this subgroup constellations: " + row); | |
summedOptions += options; | |
} | |
System.out.println("\n --> " + summedOptions + " ways to create subgroup constellations from a group of " + n | |
+ " with members" + (oneMemberPerSubgroup ? " NOT " : " ") + "being allowed in more than one subgroup"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Shortened output for
n = 13
andoneMemberPerSubgroup = false
:101 subgroup constellations are possible with a group of 13
1 ways to arrange 13 in this subgroup constellations: [13]
169 ways to arrange 13 in this subgroup constellations: [12, 1]
6084 ways to arrange 13 in this subgroup constellations: [11, 2]
13182 ways to arrange 13 in this subgroup constellations: [11, 1, 1]
81796 ways to arrange 13 in this subgroup constellations: [10, 3]
290004 ways to arrange 13 in this subgroup constellations: [10, 2, 1]
628342 ways to arrange 13 in this subgroup constellations: [10, 1, 1, 1]
511225 ways to arrange 13 in this subgroup constellations: [9, 4]
2658370 ways to arrange 13 in this subgroup constellations: [9, 3, 1]
4350060 ways to arrange 13 in this subgroup constellations: [9, 2, 2]
9425130 ways to arrange 13 in this subgroup constellations: [9, 2, 1, 1]
20421115 ways to arrange 13 in this subgroup constellations: [9, 1, 1, 1, 1]
1656369 ways to arrange 13 in this subgroup constellations: [8, 5]
11962665 ways to arrange 13 in this subgroup constellations: [8, 4, 1]
28710396 ways to arrange 13 in this subgroup constellations: [8, 3, 2]
62205858 ways to arrange 13 in this subgroup constellations: [8, 3, 1, 1]
101791404 ways to arrange 13 in this subgroup constellations: [8, 2, 2, 1]
220548042 ways to arrange 13 in this subgroup constellations: [8, 2, 1, 1, 1]
477854091 ways to arrange 13 in this subgroup constellations: [8, 1, 1, 1, 1, 1]
2944656 ways to arrange 13 in this subgroup constellations: [7, 6]
28710396 ways to arrange 13 in this subgroup constellations: [7, 5, 1]
95701320 ways to arrange 13 in this subgroup constellations: [7, 4, 2]
207352860 ways to arrange 13 in this subgroup constellations: [7, 4, 1, 1]
140361936 ways to arrange 13 in this subgroup constellations: [7, 3, 3]
497646864 ways to arrange 13 in this subgroup constellations: [7, 3, 2, 1]
1078234872 ways to arrange 13 in this subgroup constellations: [7, 3, 1, 1, 1]
814331232 ways to arrange 13 in this subgroup constellations: [7, 2, 2, 2]
1764384336 ways to arrange 13 in this subgroup constellations: [7, 2, 2, 1, 1]
3822832728 ways to arrange 13 in this subgroup constellations: [7, 2, 1, 1, 1, 1]
8282804244 ways to arrange 13 in this subgroup constellations: [7, 1, 1, 1, 1, 1, 1]
38280528 ways to arrange 13 in this subgroup constellations: [6, 6, 1]
172262376 ways to arrange 13 in this subgroup constellations: [6, 5, 2]
373235148 ways to arrange 13 in this subgroup constellations: [6, 5, 1, 1]
350904840 ways to arrange 13 in this subgroup constellations: [6, 4, 3]
1244117160 ways to arrange 13 in this subgroup constellations: [6, 4, 2, 1]
2695587180 ways to arrange 13 in this subgroup constellations: [6, 4, 1, 1, 1]
1824705168 ways to arrange 13 in this subgroup constellations: [6, 3, 3, 1]
2985881184 ways to arrange 13 in this subgroup constellations: [6, 3, 2, 2]
6469409232 ways to arrange 13 in this subgroup constellations: [6, 3, 2, 1, 1]
14017053336 ways to arrange 13 in this subgroup constellations: [6, 3, 1, 1, 1, 1]
10586306016 ways to arrange 13 in this subgroup constellations: [6, 2, 2, 2, 1]
22936996368 ways to arrange 13 in this subgroup constellations: [6, 2, 2, 1, 1, 1]
49696825464 ways to arrange 13 in this subgroup constellations: [6, 2, 1, 1, 1, 1, 1]
107676455172 ways to arrange 13 in this subgroup constellations: [6, 1, 1, 1, 1, 1, 1, 1]
473721534 ways to arrange 13 in this subgroup constellations: [5, 5, 3]
1679558166 ways to arrange 13 in this subgroup constellations: [5, 5, 2, 1]
3639042693 ways to arrange 13 in this subgroup constellations: [5, 5, 1, 1, 1]
657946575 ways to arrange 13 in this subgroup constellations: [5, 4, 4]
3421322190 ways to arrange 13 in this subgroup constellations: [5, 4, 3, 1]
5598527220 ways to arrange 13 in this subgroup constellations: [5, 4, 2, 2]
12130142310 ways to arrange 13 in this subgroup constellations: [5, 4, 2, 1, 1]
26281975005 ways to arrange 13 in this subgroup constellations: [5, 4, 1, 1, 1, 1]
8211173256 ways to arrange 13 in this subgroup constellations: [5, 3, 3, 2]
17790875388 ways to arrange 13 in this subgroup constellations: [5, 3, 3, 1, 1]
29112341544 ways to arrange 13 in this subgroup constellations: [5, 3, 2, 2, 1]
63076740012 ways to arrange 13 in this subgroup constellations: [5, 3, 2, 1, 1, 1]
136666270026 ways to arrange 13 in this subgroup constellations: [5, 3, 1, 1, 1, 1, 1]
47638377072 ways to arrange 13 in this subgroup constellations: [5, 2, 2, 2, 2]
103216483656 ways to arrange 13 in this subgroup constellations: [5, 2, 2, 2, 1, 1]
223635714588 ways to arrange 13 in this subgroup constellations: [5, 2, 2, 1, 1, 1, 1]
484544048274 ways to arrange 13 in this subgroup constellations: [5, 2, 1, 1, 1, 1, 1, 1]
1049845437927 ways to arrange 13 in this subgroup constellations: [5, 1, 1, 1, 1, 1, 1, 1, 1]
4751836375 ways to arrange 13 in this subgroup constellations: [4, 4, 4, 1]
11404407300 ways to arrange 13 in this subgroup constellations: [4, 4, 3, 2]
24709549150 ways to arrange 13 in this subgroup constellations: [4, 4, 3, 1, 1]
40433807700 ways to arrange 13 in this subgroup constellations: [4, 4, 2, 2, 1]
87606583350 ways to arrange 13 in this subgroup constellations: [4, 4, 2, 1, 1, 1]
189814263925 ways to arrange 13 in this subgroup constellations: [4, 4, 1, 1, 1, 1, 1]
16726464040 ways to arrange 13 in this subgroup constellations: [4, 3, 3, 3]
59302917960 ways to arrange 13 in this subgroup constellations: [4, 3, 3, 2, 1]
128489655580 ways to arrange 13 in this subgroup constellations: [4, 3, 3, 1, 1, 1]
97041138480 ways to arrange 13 in this subgroup constellations: [4, 3, 2, 2, 2]
210255800040 ways to arrange 13 in this subgroup constellations: [4, 3, 2, 2, 1, 1]
455554233420 ways to arrange 13 in this subgroup constellations: [4, 3, 2, 1, 1, 1, 1]
987034172410 ways to arrange 13 in this subgroup constellations: [4, 3, 1, 1, 1, 1, 1, 1]
344054945520 ways to arrange 13 in this subgroup constellations: [4, 2, 2, 2, 2, 1]
745452381960 ways to arrange 13 in this subgroup constellations: [4, 2, 2, 2, 1, 1, 1]
1615146827580 ways to arrange 13 in this subgroup constellations: [4, 2, 2, 1, 1, 1, 1, 1]
3499484793090 ways to arrange 13 in this subgroup constellations: [4, 2, 1, 1, 1, 1, 1, 1, 1]
7582217051695 ways to arrange 13 in this subgroup constellations: [4, 1, 1, 1, 1, 1, 1, 1, 1, 1]
86977613008 ways to arrange 13 in this subgroup constellations: [3, 3, 3, 3, 1]
142327003104 ways to arrange 13 in this subgroup constellations: [3, 3, 3, 2, 2]
308375173392 ways to arrange 13 in this subgroup constellations: [3, 3, 3, 2, 1, 1]
668146209016 ways to arrange 13 in this subgroup constellations: [3, 3, 3, 1, 1, 1, 1]
504613920096 ways to arrange 13 in this subgroup constellations: [3, 3, 2, 2, 2, 1]
1093330160208 ways to arrange 13 in this subgroup constellations: [3, 3, 2, 2, 1, 1, 1]
2368882013784 ways to arrange 13 in this subgroup constellations: [3, 3, 2, 1, 1, 1, 1, 1]
5132577696532 ways to arrange 13 in this subgroup constellations: [3, 3, 1, 1, 1, 1, 1, 1, 1]
825731869248 ways to arrange 13 in this subgroup constellations: [3, 2, 2, 2, 2, 2]
1789085716704 ways to arrange 13 in this subgroup constellations: [3, 2, 2, 2, 2, 1, 1]
3876352386192 ways to arrange 13 in this subgroup constellations: [3, 2, 2, 2, 1, 1, 1, 1]
8398763503416 ways to arrange 13 in this subgroup constellations: [3, 2, 2, 1, 1, 1, 1, 1, 1]
18197320924068 ways to arrange 13 in this subgroup constellations: [3, 2, 1, 1, 1, 1, 1, 1, 1, 1]
39427528668814 ways to arrange 13 in this subgroup constellations: [3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
2927594809152 ways to arrange 13 in this subgroup constellations: [2, 2, 2, 2, 2, 2, 1]
6343122086496 ways to arrange 13 in this subgroup constellations: [2, 2, 2, 2, 2, 1, 1, 1]
13743431187408 ways to arrange 13 in this subgroup constellations: [2, 2, 2, 2, 1, 1, 1, 1, 1]
29777434239384 ways to arrange 13 in this subgroup constellations: [2, 2, 2, 1, 1, 1, 1, 1, 1, 1]
64517774185332 ways to arrange 13 in this subgroup constellations: [2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1]
139788510734886 ways to arrange 13 in this subgroup constellations: [2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
302875106592253 ways to arrange 13 in this subgroup constellations: [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
--> 661348833658423 ways to create subgroup constellations from a group of 13 with members being allowed in more than one subgroup