permutation

Is there C++ class that implements operations with permutations?

大城市里の小女人 提交于 2019-12-30 09:37:09
问题 Is there C++ template class that implements operations with permutations and permutation group? Such class has to implement finding product and inverse, multiplication, etc. 回答1: I don't know of one, but it should be easy enough to implement. Internally you could represent the permutation as a vector e.g. (1 3 4 2 7 5 6) being a perm of 1-7 sending 1->1, 2->3, 3->4, 4->2 etc. or as a set of cycles e.g. (1) (2 3 4) (5 7 6), and implement the operations in terms of these. Presumably the

String permutations in Java (non-recursive)

杀马特。学长 韩版系。学妹 提交于 2019-12-30 08:50:07
问题 I'm a high school student of grade 10 trying to work through some problems in a Data Structures and Algorithms book on Java. One of the questions is to print all permutations of a string. class C14 { public static void main(char a[]) { // char[] a = {'c','a','r','b','o','n'}; int c=0,w=0; for(int q = 0;q<a.length;q++) { for(int i=0;i<a.length;i++) { for(int j=1;j<a.length;j++) { for(int k=1;k<a.length-1;k++) { for(int z=0;z<a.length;z++) { System.out.print(a[z]); c++; } w++; System.out

Generate all possible outcomes of k balls in n bins (sum of multinomial / categorical outcomes)

点点圈 提交于 2019-12-30 06:07:23
问题 Suppose we have n bins in which we are throwing k balls. What is a fast (i.e. using numpy/scipy instead of python code) way to generate all possible outcomes as a matrix? For example, if n = 4 and k = 3 , we'd want the following numpy.array : 3 0 0 0 2 1 0 0 2 0 1 0 2 0 0 1 1 2 0 0 1 1 1 0 1 1 0 1 1 0 2 0 1 0 1 1 1 0 0 2 0 3 0 0 0 2 1 0 0 2 0 1 0 1 2 0 0 1 1 1 0 1 0 2 0 0 3 0 0 0 2 1 0 0 1 2 0 0 0 3 Apologies if any permutation was missed, but this is the general idea. The generated

Generate all possible outcomes of k balls in n bins (sum of multinomial / categorical outcomes)

心已入冬 提交于 2019-12-30 06:02:05
问题 Suppose we have n bins in which we are throwing k balls. What is a fast (i.e. using numpy/scipy instead of python code) way to generate all possible outcomes as a matrix? For example, if n = 4 and k = 3 , we'd want the following numpy.array : 3 0 0 0 2 1 0 0 2 0 1 0 2 0 0 1 1 2 0 0 1 1 1 0 1 1 0 1 1 0 2 0 1 0 1 1 1 0 0 2 0 3 0 0 0 2 1 0 0 2 0 1 0 1 2 0 0 1 1 1 0 1 0 2 0 0 3 0 0 0 2 1 0 0 1 2 0 0 0 3 Apologies if any permutation was missed, but this is the general idea. The generated

java string permutations and combinations lookup

雨燕双飞 提交于 2019-12-30 04:33:09
问题 I'm writing an Android word app. My code includes a method that would find all combinations of the string and the substrings of a 7 letter string with a minimum of length 3. Then compare all available combination to every word in the dictionary to find all the valid words. I'm using a recursive method. Here's the code. // Gets all the permutations of a string. void permuteString(String beginningString, String endingString) { if (endingString.length() <= 1){ if((Arrays.binarySearch(mDictionary

Random permutation of integers using a random number generator

白昼怎懂夜的黑 提交于 2019-12-29 02:12:14
问题 This is my homework assignment: Random r = new Random(); public int get100RandomNumber() { return 1+r.nextInt(100); } You are given a pre-defined function named getrand100() (above) which returns an integer which is one random number from 1-100. You can call this function as many times as you want but beware that this function is quite resource intensive. You cannot use any other random generator. You cannot change the definition of getrand100() . Output: Print numbers 1-20 in random order.

Code to enumerate permutations in Scala

一笑奈何 提交于 2019-12-28 10:44:11
问题 I coded a function to enumerate all permutations of a given list. What do you think of the code below? def interleave(x:Int, l:List[Int]):List[List[Int]] = { l match { case Nil => List(List(x)) case (head::tail) => (x :: head :: tail) :: interleave(x, tail).map(head :: _) } } def permutations(l:List[Int]):List[List[Int]] = { l match { case Nil => List(List()) case (head::tail) => for(p0 &lt- permutations(tail); p1 &lt- interleave(head, p0)) yield p1 } } 回答1: Given a Seq, one can already have

Permutation of Array PHP

北慕城南 提交于 2019-12-28 07:05:20
问题 I have the following problem: $multidmimensional = array( [0] => array( [0] => 1, [1] => 2, [2] => 3 ); [1] => array( [0] => 5, [1] => 6, [2] => 7 ); ... [2] => array( [0] =>,4 [1] => 5, ); ); I can have one or more (nested) arrays, and lets take as an example the first two of the above arrays: I should permutate them in the following way: 15 16 17 25 26 27 36 37 38 If I had for example those three arrays, I should get a result like this: 154 164 174 155 165 175 254 264 274 255 265 275 364

Permutation of Array PHP

旧城冷巷雨未停 提交于 2019-12-28 07:04:26
问题 I have the following problem: $multidmimensional = array( [0] => array( [0] => 1, [1] => 2, [2] => 3 ); [1] => array( [0] => 5, [1] => 6, [2] => 7 ); ... [2] => array( [0] =>,4 [1] => 5, ); ); I can have one or more (nested) arrays, and lets take as an example the first two of the above arrays: I should permutate them in the following way: 15 16 17 25 26 27 36 37 38 If I had for example those three arrays, I should get a result like this: 154 164 174 155 165 175 254 264 274 255 265 275 364

Generating Permutations using LINQ

ぃ、小莉子 提交于 2019-12-28 02:40:29
问题 I have a set of products that must be scheduled. There are P products each indexed from 1 to P. Each product can be scheduled into a time period 0 to T. I need to construct all permutations of product schedules that satisfy the following constraint: If p1.Index > p2.Index then p1.Schedule >= p2.Schedule. I am struggling to construct the iterator. I know how to do this via LINQ when the number of products is a known constant, but am not sure how to generate this query when the number of