permutation

PHP nested array combinations / permutations

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-04 02:33:29
问题 I thought my problem had been solved using this solution, using the answer by VolkerK, but it doesn't seem to be working correctly. What I want is a function that returns all possible combinations of values contained in nested arrays. For example, if I pass in [ ['a', 'b'], ['a', 'b'], ['a', 'b'], ['a'], ['a'], ['a'] ] It would return a, a, a, a, a, a b, b, b, a, a, a a, a, b, a, a, a a, b, a, a, a, a b, a, a, a, a, a a, b, b, a, a, a b, b, a, a, a, a b, a, b, a, a, a The problem with using

Given an array of integers [x0 x1 x2], how do you calculate all possible permutations from [0 0 0] to [x0 x1 x2]?

拥有回忆 提交于 2020-01-03 17:28:20
问题 I am writing a program that takes in an ArrayList and I need to calculate all possible permutations starting with a list of zeroes, up to the value in the corresponding input list. Does anyone know how to iteratively calculate these values? For example, given [ 1 2 ] as input, it should find and store the following lists: [0 0], [1 0], [1 1], [1 2], [0 1], [0 2] Thanks! 回答1: Here's a standard recursive generator: import java.util.Arrays; //... static void generate(int... limits) { generate

Generate random JSON structure permutations for a data set

五迷三道 提交于 2020-01-03 16:56:38
问题 I want to generate many different permutations of JSON structures as a representation of the same data set, preferably without having to hard code the implementation. For example, given the following JSON: {"name": "smith", "occupation": "agent", "enemy": "humanity", "nemesis": "neo"}` Many different permutations should be produced, such as: change in name : {"name":"smith"}- > {"last_name":"smith"} change in order: {"name":"...","occupation":"..."} -> {"occupation":"...", "name":"..."}

What is the complexity (Big-O) of this algorithm?

牧云@^-^@ 提交于 2020-01-03 12:12:25
问题 I'm fairly familiar with algorithm analysis and can tell the Big-O of most algorithms I work with. But I've been stuck for hours unable to come up with the Big-O for this code I write. Basically it's a method to generate permutations for a string. It works by making each character in the string the first character and combine it with the permutations of the substring less that character (recursively). If I put in the code to count the number of iterations, I've got something between O(N!) and

What is the complexity (Big-O) of this algorithm?

断了今生、忘了曾经 提交于 2020-01-03 12:12:06
问题 I'm fairly familiar with algorithm analysis and can tell the Big-O of most algorithms I work with. But I've been stuck for hours unable to come up with the Big-O for this code I write. Basically it's a method to generate permutations for a string. It works by making each character in the string the first character and combine it with the permutations of the substring less that character (recursively). If I put in the code to count the number of iterations, I've got something between O(N!) and

Retrieve a specific permutation without storing all possible permutations in Matlab

谁都会走 提交于 2020-01-03 00:37:22
问题 I am working on 2D rectangular packing. In order to minimize the length of the infinite sheet (Width is constant) by changing the order in which parts are placed. For example, we could place 11 parts in 11! ways. I could label those parts and save all possible permutations using perms function and run it one by one, but I need a large amount of memory even for 11 parts. I'd like to be able to do it for around 1000 parts. Luckily, I don't need every possible sequence. I would like to index

Adding constraints to permutations

℡╲_俬逩灬. 提交于 2020-01-02 15:47:12
问题 I am trying to calculate all permutations with list = [0,1,2,3,4,5,6] adhering to some constraints. Position 0 must be > 3 Position 3 + Position 5 < Position 4 With my current code I determining all permutations and iterations through each, applying the constraints. import itertools Used_permutations = [] numbers = [0,1,2,3,4,5,6] all_permutations = list(itertools.permutations(numbers)) #Determine all permutations for permutation in all_permutations: if permutation[0] > 3 and permutation[3] +

How do you iterate over all configurations of m variables belonging to the same domain of size n?

孤人 提交于 2020-01-02 05:27:12
问题 EDIT: My solution is added to the end of the question. Thanks for the hint. I'll just go with an example. Suppose I have an array with length n : arr = { 1, 4, 8, 2, 5, ... } If I want to traverse all combinations of TWO elements I would write: for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { // do something with arr[i] and arr[j] } } I If I want to traverse all configurations of THREE elements I would simply add another layer of for iteration: for (int i = 0; i < n; i++) { for

All possible combinations for two column data

陌路散爱 提交于 2020-01-02 05:05:41
问题 I have a two column view Product Id Tag ---------------------- 1 Leather 1 Watch 2 Red 2 Necklace 2 Pearl I'm trying to get all possible combinations of tags for a product as such: 1 Leather 1 Leather,Watch 2 Pearl 2 Pearl,Necklace 2 Pearl Necklace,Red 2 Necklace 2 Necklace, Red 2 Red I've found and stolen some SQL that give me the complete list for all but not the small versions, its below. Any ideas, it's started to make my head hurt. A virtual pint for the best answer. SELECT ProductId,

More efficient way to get integer permutations?

霸气de小男生 提交于 2020-01-02 00:54:09
问题 I can get integer permutations like this: myInt = 123456789 l = itertools.permutations(str(myInt)) [int(''.join(x)) for x in l] Is there a more efficient way to get integer permutations in Python, skipping the overhead of creating a string, then joining the generated tuples? Timing it, the tuple-joining process makes this 3x longer than list(l) . added supporting information myInt =123456789 def v1(i): #timeit gives 258ms l = itertools.permutations(str(i)) return [int(''.join(x)) for x in l]