All Combinations
Share
Explore

icon picker
Filter Approach

ABCDE
0
5
Use product
def product(*args, repeat=1):
# product('ABCD', 'xy') --> Ax Ay Bx By Cx Cy Dx Dy
# product(range(2), repeat=3) --> 000 001 010 011 100 101 110 111
pools = [tuple(pool) for pool in args] * repeat
result = [[]]
for pool in pools:
result = [res+[p] for res in result for p in pool]
for prod in result:
yield tuple(prod)
as
Sequence(Power(list.Count(), r), (2 * Power(list.Count(),r)) - 1).FormulaMap(CurrentValue.WithName(Number,
If(CurrentValue = 0,0,
Sequence(Log(Number, list.Count()).RoundDown(), 0, -1)
.FormulaMap(CurrentValue.WithName(Step,
RoundDown(Number / Power(list.Count(), Step)).Remainder(list.Count()) + 1
)
).Slice(2)
)
)).FormulaMap(
CurrentValue.FormulaMap(
list.nth(CurrentValue)
)
)
Product:
[AAAAA][AAAAB][AAAAC][AAAAD][AAAAE][AAABA][AAABB][AAABC][AAABD][AAABE][AAACA][AAACB][AAACC][AAACD][AAACE][AAADA][AAADB][AAADC][AAADD][AAADE][AAAEA][AAAEB][AAAEC][AAAED][AAAEE][AABAA][AABAB][AABAC][AABAD][AABAE] Show 3095 more
To write permutations
def permutations(iterable, r=None):
pool = tuple(iterable)
n = len(pool)
r = n if r is None else r
for indices in product(range(n), repeat=r):
if len(set(indices)) == r:
yield tuple(pool[i] for i in indices)
as
Sequence(Power(list.Count(), r), (2 * Power(list.Count(), r)) - 1).FormulaMap(CurrentValue.WithName(Number,
If(CurrentValue = 0,0,
Sequence(Log(Number, list.Count()).RoundDown(), 0, -1)
.FormulaMap(CurrentValue.WithName(Step,
RoundDown(Number / Power(list.Count(), Step)).Remainder(list.Count()) + 1
)
).Slice(2)
)
)).FormulaMap(CurrentValue.Unique()).Filter(CurrentValue.Count() = r).FormulaMap(
CurrentValue.FormulaMap(
list.Nth(CurrentValue)
)
)
Permutations:
[ABCDE][ABCED][ABDCE][ABDEC][ABECD][ABEDC][ACBDE][ACBED][ACDBE][ACDEB][ACEBD][ACEDB][ADBCE][ADBEC][ADCBE][ADCEB][ADEBC][ADECB][AEBCD][AEBDC][AECBD][AECDB][AEDBC][AEDCB][BACDE][BACED][BADCE][BADEC][BAECD][BAEDC] Show 90 more
To write combinations
def combinations(iterable, r):
pool = tuple(iterable)
n = len(pool)
for indices in permutations(range(n), r):
if sorted(indices) == list(indices):
yield tuple(pool[i] for i in indices)
as
Sequence(Power(list.Count(), r), (2 * Power(list.Count(), r)) - 1).FormulaMap(CurrentValue.WithName(Number,
If(CurrentValue = 0,0,
Sequence(Log(Number, list.Count()).RoundDown(), 0, -1)
.FormulaMap(CurrentValue.WithName(Step,
RoundDown(Number / Power(list.Count(), Step)).Remainder(list.Count()) + 1
)
).Slice(2)
)
)).FormulaMap(CurrentValue.Unique()).Filter(CurrentValue.Count() = r).Filter(CurrentValue.Sort(true)=CurrentValue)
Combinations:
[12345]
All Combinations of all Lengths (only showing indices):
[[1][2][3][4][5]][[12][13][14][15][23][24][25][34][35][45]][[123][124][125][134][135][145][234][235][245][345]][[1234][1235][1245][1345][2345]][[12345]]
Of course the downside to this is that it generates a ton of unneeded data that just gets thrown away. Would be interesting to see if there are any patterns to be found in the numbers that are returned, maybe that could be exploited in the creation process (I use an n-ary number—where n is whatever is in the slider r in this case it’s currently:
5
—as the basis for generating the Products step)
[5251256253125][2551255625531255125256252531252562512531251253125625][125255625255312525562512553125125531256255625125253125125253125625253125625125][6251252553125125255312562525531256251255312562512525][3125625125255]
Tried to format it for use in the OEIS, but it doesn’t show anything for any of the possible sequences

Share
 
Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.