permutation

Search for permutation of characters of a substring in Python

扶醉桌前 提交于 2019-12-20 03:23:33
问题 I am trying to extract the occurrences of a string and of all the permutations of its characters from a line of text. For example, I need to extract the string t = 'ABC' and all its permutations: 'ABC', 'CAB', 'BCA', 'BAC', 'CBA', from the following string s: s = 'ABCXABCXXACXXBACXXBCA' The results is: ABC , ABC , BAC , BCA The string t should be of any length and can contain any characters in [A-Z] , [a-z] and [0-9] Is there a way to obtain the result by using regular expressions in Python?

Finding all combinations from sets of possibilities

我只是一个虾纸丫 提交于 2019-12-20 03:21:23
问题 I have multiple sets of arrays that contain additional arrays that have values attached that I use for figuring out math. In order to find the best combination of these things, I need to mix and match from these arrays. I've seen "solutions" similar to this around, but they're usually 1 array deep with no real combinations/possibilities. So to give an example. I have sets A, B, and C. Set A contains Aa, Ab, Ac, and Ad. Aa contains a set of values. Extrapolate that out for the others. Aa can

Algorithm to generate 1000 distinct integers in the range [0,8000]? [duplicate]

房东的猫 提交于 2019-12-19 21:52:54
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: How do you efficiently generate a list of K non-repeating integers between 0 and an upper bound N What are some alternative methods to generate 1000 distinct random integers in the range [0,8000] as opposed to the following: naive method: generating a number and checking if it's already in the array. O(n^2) linear shuffle: generate sequence 0 to 8000, shuffle, take the first 1000. O(n) 回答1: You can use a partial

pseudo random distribution which guarantees all possible permutations of value sequence - C++

让人想犯罪 __ 提交于 2019-12-19 08:33:09
问题 Random question. I am attempting to create a program which would generate a pseudo-random distribution. I am trying to find the right pseudo-random algorithm for my needs. These are my concerns: 1) I need one input to generate the same output every time it is used. 2) It needs to be random enough that a person who looks at the output from input 1 sees no connection between that and the output from input 2 (etc.), but there is no need for it to be cryptographically secure or truly random. 3

Use next_permutation to permutate a vector of classes

女生的网名这么多〃 提交于 2019-12-19 07:23:27
问题 Is it possible to use std::next_permutation() to permutate the elements of a vector of a class i created? How does the comparison parameter in next_permutation() work? 回答1: Is it possible to use std::next_permutation() to permutate the elements of a vector of a class i created? Yes! Try this #include<iostream> #include<vector> #include<algorithm> int main() { typedef std::vector<int> V; //<or_any_class> V v; for(int i=1;i<=5;++i) v.push_back(i*10); do{ std::cout<<v[0]<<" "<<v[1]<<" "<<v[2]<<"

How do I generate all permutations of certain size with repetitions in Scheme?

半腔热情 提交于 2019-12-19 07:04:26
问题 I am learning Scheme and I am trying to generate permutations with repetitions of certain size. For example, given n=4 and set S = {a, b, c, d, e, f}, I'd like to generate all possible permutations: {a,a,a,a},{a,a,a,b},...,{a,a,a,f},{a,a,b,a},{a,a,b,b},...,{a,a,b,f},...{f,a,a,a},{f,a,a,b}...,{f,a,a,f},...{f,f,f,f}. The trouble is that I can't understand how to pick 'a' 4 times, and remember that i had picked it 4 times, then pick 'a' 3 times, and 'b' one time, and remember all this, so I don

Permutations/Anagrams in Objective-C — I am missing something

拈花ヽ惹草 提交于 2019-12-19 06:26:44
问题 (code below regarding my question) Per this stack overflow question I used Pegolon's approach to generating all possible permutations of a group of characters inside an NSString. However, I am now trying to get it to not just generate an ANAGRAM which is all permutations of the same length, but all possible combinations (any length) of the characters in a string. Would anyone know how i would alter the following code to get it to do this? This is much like: Generate All Permutations of All

Permutation of an array, with repetition, in Java

◇◆丶佛笑我妖孽 提交于 2019-12-19 05:54:48
问题 There are some similar questions on the site that have been of some help, but I can't quite nail down this problem, so I hope this is not repetitive. This is a homework assignment where you have a set array of characters [A, B, C], and must use recursion to get all permutations (with repetition). The code I have sort of does this: char[] c = {'A', 'B' , 'C'}; public void printAll(char[] c, int n, int k) { if (k == n) { System.out.print(c); return; } else { for (int j = 0; j<n; j++) { for (int

Permutation of an array, with repetition, in Java

﹥>﹥吖頭↗ 提交于 2019-12-19 05:54:04
问题 There are some similar questions on the site that have been of some help, but I can't quite nail down this problem, so I hope this is not repetitive. This is a homework assignment where you have a set array of characters [A, B, C], and must use recursion to get all permutations (with repetition). The code I have sort of does this: char[] c = {'A', 'B' , 'C'}; public void printAll(char[] c, int n, int k) { if (k == n) { System.out.print(c); return; } else { for (int j = 0; j<n; j++) { for (int

Permutations of a given set of numbers [closed]

跟風遠走 提交于 2019-12-19 05:10:39
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 5 years ago . Can someone please explain a good algorithm to find all permutations of a given set of numbers in an efficient manner? 回答1: The simplest approaches are the recursive ones, i.e., in executable pseudocode; def permute(theseq): if len(theseq) <= 1: yield theseq return for i in range