combinatorics

PHP Possible combinations 3 arrays of 2 values [duplicate]

谁都会走 提交于 2021-02-19 07:41:40
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: PHP take all combinations I'm thinking of making something in PHP that will show me all combinations of license plates. For example: You have 3 boxes you can fill in max 2 values Like BOX1 BOX2 BOX3 75 PM M5 7S PH MS Z5 PN H5 ZS RM HS 25 RH N5 2S RN NS NOT BOX1+BOX1+BOX1 It needs to show me ex. 75-PM-M5 ex. 75-PH-MS ex. 75-PN-MS ex. 75-PM-H5 ex. 75-PH-H5 ex. 75-PN-H5 So, BOX1+BOX2+BOX3 The PHP script needs to

Finding all combinations of multiple variables summing to 1

混江龙づ霸主 提交于 2021-02-19 04:09:13
问题 I am trying to solve the equation x1 + x2 + x3 + .... + xn = 1 where the values of all xi are restricted to [0, 0.1, 0.2, ..., 0.9, 1] . Currently, I am solving the problem by first generating an n-dimensional array mat , where at each element location the value is the sum of the axis values, which vary in axisValues = 0:0.1:1 : mat(i,j,k,...,q) = axisValues(i) + axisValues(j) + ... + axisValues(q). Then I search for all entries of the resulting array that are equal to one. The code (shown

Finding all combinations of multiple variables summing to 1

感情迁移 提交于 2021-02-19 04:05:14
问题 I am trying to solve the equation x1 + x2 + x3 + .... + xn = 1 where the values of all xi are restricted to [0, 0.1, 0.2, ..., 0.9, 1] . Currently, I am solving the problem by first generating an n-dimensional array mat , where at each element location the value is the sum of the axis values, which vary in axisValues = 0:0.1:1 : mat(i,j,k,...,q) = axisValues(i) + axisValues(j) + ... + axisValues(q). Then I search for all entries of the resulting array that are equal to one. The code (shown

Optimal way to compute permutations in julia

五迷三道 提交于 2021-02-18 11:38:09
问题 Consider a list [1,1,1,...,1,0,0,...,0] (an arbitrary list of zeros and ones). We want the whole possible permutations in this array, there'll be binomial(l,k) permutations ( l stands for the length of the list and k for the number of ones in the list). Right now, I have tested three different algorithms to generate the whole possible permutations, one that uses a recurrent function, one that calculates the permutations via calculating the interval number [1,...,1,0,0,...,0] to [0,0,...0,1,1,

Find combinations of size r from a set with decreasing sum value

家住魔仙堡 提交于 2021-02-10 14:44:33
问题 I have a set of numbers eg. [100,90,80,70,60,50] and want to find all combinations of size r=3 but in order of decreasing sum. Arranging the numbers in decreasing order does not work eg. (100, 90, 80) 270 (100, 90, 70) 260 (100, 90, 60) 250 (100, 90, 50) **240** (100, 80, 70) **250** (100, 80, 60) 240 How can i go about finding such a combination set with decreasing sum value. 回答1: Here' the Code import itertools array = [100,90,80,70,60,50] size = 3 answer = [] # to store all combination

Index into size ordered power set

廉价感情. 提交于 2021-02-06 08:59:23
问题 I would like to be able to index elements of a power set without expanding the full set into memory (a la itertools) Furthermore I want the index to be cardinality ordered. So index 0 should be the empty set, index 2**n - 1 should be all elements Most literature I have found so far involves generating a power set inductively. It doesn't let you just dive in at any index. My motivation for this indexing is to slice a problem for distributed execution and it be helpful if a remote machine can

Split a set into n unequal subsets with the key deciding factor being that the elements in the subset aggregate and equal a predetermined amount?

我的梦境 提交于 2021-02-04 05:58:21
问题 I am looking towards a set of numbers and aiming to split them into subsets via set partitioning. The deciding factor on how these subsets will be generated will be ensuring that the sum of all the elements in the subset is as close as possible to a number generated by a pre-determined distribution. The subsets need not be the same size and each element can only be in one subset. I had previously been given guidance on this problem via the greedy algorithm (Link here), but I have found that

Recursive function that returns combinations of size n chosen from list

我与影子孤独终老i 提交于 2021-01-29 05:13:37
问题 I am trying to write a recursive function which takes as its inputs an integer n , and a list l , and returns a list of all the combinations of size n that can be chosen from the elements in l . I'm aware that I can just use itertools, but I want to become better at writing recursive functions, and I believe writing my own function will help me. So for example, if you input: n = 3 l = [1, 2, 3, 4] I want the output to be: `[ [1, 2, 3], [1, 3, 4], [2, 3, 4], [1, 2, 4] ] So far I've written

Pair-Tournament design algorithm

随声附和 提交于 2021-01-28 17:19:10
问题 I'm trying to build a Javascript function that takes as an input: array of players e.g. ["player1","player2","player3","player4"] (probably only equal number of players) and dynamically creates an array for a tournament design based on the following rules: each player partners no more than once with the same player every player has an equal amount of total matches the outputs would be an array containing arrays of matches with four entries each e.g. [player1, player2, player3, player4] stands

Pair-Tournament design algorithm

|▌冷眼眸甩不掉的悲伤 提交于 2021-01-28 17:16:24
问题 I'm trying to build a Javascript function that takes as an input: array of players e.g. ["player1","player2","player3","player4"] (probably only equal number of players) and dynamically creates an array for a tournament design based on the following rules: each player partners no more than once with the same player every player has an equal amount of total matches the outputs would be an array containing arrays of matches with four entries each e.g. [player1, player2, player3, player4] stands