permutation

Permutation of jagged array

狂风中的少年 提交于 2019-12-23 02:47:07
问题 I'm trying to create a permutation of a multidimensional array in classic asp (vbscript) and I'm seriously stuck. I've tried several functions of my own and also tried copying several php versions over, but I often end up with something that either goes into a buffer overflow / infinite recursion or I get results that are more like a combination than a permutation, if I understand the differences correctly. Lets say it's for a shirt. The shirt can have colors, sizes, and styles. (The actual

Regex to match permuted set of characters

别说谁变了你拦得住时间么 提交于 2019-12-23 01:26:31
问题 I want to match strings which begin with all six characters abcdef , regardless of the order in which these six characters occur at the beginning of the string. All six characters must appear once, and once only, in the first six characters of the string, to produce a match. e.g. "dfabce..." is a match, but "aacdef..." is not. Can regular expressions do this, or do I need a parser? 回答1: Sure, you could do this with positive lookahead assertions: ^(?=.{0,5}a)(?=.{0,5}b)(?=.{0,5}c)(?=.{0,5}d)(?

Find all possible arrangements of a n numbers in an array

陌路散爱 提交于 2019-12-23 01:21:30
问题 I have an array which contains lets say [25,15,8,20] I want to find all possible arrangements of numbers that is possible. expected output: 25 15 8 20 25 15 20 8 25 20 15 8 25 20 8 15 25 8 20 15 25 8 15 20 15 25 8 20 15 25 20 8 15 20 25 8 15 20 8 25 15 8 20 25 15 8 25 20 20 25 15 8 20 25 8 15 20 8 25 15 20 8 15 25 20 15 25 8 20 15 8 25 8 15 20 25 8 15 25 20 8 25 15 20 8 25 20 15 8 20 15 25 8 20 25 15 void print(int *num, int n) { int i; for ( i = 0 ; i < n ; i++) printf("%d ", num[i]); printf

Sample k random permutations without replacement in O(N)

白昼怎懂夜的黑 提交于 2019-12-22 23:27:39
问题 I need a number of unique random permutations of a list without replacement, efficiently. My current approach: total_permutations = math.factorial(len(population)) permutation_indices = random.sample(xrange(total_permutations), k) k_permutations = [get_nth_permutation(population, x) for x in permutation_indices] where get_nth_permutation does exactly what it sounds like, efficiently (meaning O(N)). However, this only works for len(population) <= 20 , simply because 21! is so mindblowingly

Time complexity of this code to list all permutations?

☆樱花仙子☆ 提交于 2019-12-22 18:26:10
问题 For example, if the input string is “ABC”, then output should be “ABC, ACB, BAC, BCA, CAB, CBA”. Here is my approach : #include<stdio.h> #include<conio.h> #include<string.h> void print(char str[],int visited[],int index,char temp[],int len) { if(index==len) { temp[index]='\0'; printf("\n%s",temp); return; } for(int i=0;i<len;i++) { if(!visited[str[i]-'A']) { visited[str[i]-'A']=1; temp[index]=str[i]; print(str,visited,index+1,temp,len); visited[str[i]-'A']=0; } } } int main() { int visited[20

swift string permutations allowing the same strings

感情迁移 提交于 2019-12-22 18:19:25
问题 I have seen other questions about string permutations, but they don't completely cover my question. Suppose I have an array of strings: ["A", "B", "C", "D", "E"] and I am looking for a way to get all possible combinations of for instance three elements: AAA, AAB, AAC, AAD, AAE, ABA, ACA, ... Other solutions for permutations (e.g. here, or here) don't allow the same element to be duplicated, and result in: ABC, ABD, ABE, BAC, ... I now use a brute-force approach, with many iterations, but of

Number of all possible groupings of a set of values?

左心房为你撑大大i 提交于 2019-12-22 15:50:13
问题 I want to find a combinatorial formula that given a certain number of integers, I can find the number of all possible groupings of these integers (such that all values belong to a single group) Say I have 3 integers, 1, 2, 3 There would be 5 groupings: 1 2 3 1|2|3| 1 2|3 1|2 3 2|1 3 I have calculated these computationally for N = 3 to 11, but I am trying to theoretically assertain. These values are: (I believe they are correct) num_integers num_groupings 3 5 4 15 5 52 6 203 7 877 8 4140 9

Fisher-Yates shuffle on a single string vs. using an equal length permutation?

依然范特西╮ 提交于 2019-12-22 14:02:42
问题 Right now I am working on a suite of word games as a means of teaching myself (and recreating some of my favorite word games!) With the help of an 'actual' studied programming friend, we have implemented a nice permutation method in one of my classes. It is finding all permutations from 3 letters and up and comparing them to Lists of strings I have containing what is essentially the Scrabble tournament word list. That's the background, here is my current issue: I now have all of the

Fisher-Yates shuffle on a single string vs. using an equal length permutation?

寵の児 提交于 2019-12-22 14:01:31
问题 Right now I am working on a suite of word games as a means of teaching myself (and recreating some of my favorite word games!) With the help of an 'actual' studied programming friend, we have implemented a nice permutation method in one of my classes. It is finding all permutations from 3 letters and up and comparing them to Lists of strings I have containing what is essentially the Scrabble tournament word list. That's the background, here is my current issue: I now have all of the

Ruby: How do you set an Enumerator's state?

别说谁变了你拦得住时间么 提交于 2019-12-22 12:37:21
问题 I'm doing a base 64 permutation incrementor. I've already written all the working code. But seeing as how Ruby already as Array::permutation which produces an Enumerator; I'd like to use that and take it a step further. Without having to go through every permutation by using 'next', can I set the start point? x = ('A'..'Z').to_a + ('a'..'z').to_a + ('0'..'9').to_a + ['+','/'] y = x.permutation(12) y.peek.join => "ABCDEFGHIJKL" y.next y.peek.join => "ABCDEFGHIJKM" . # DO SOMETHING LIKE THIS y