permutation

Algorithm for Permutation with Buckets

吃可爱长大的小学妹 提交于 2021-02-10 17:54:34
问题 I am looking for an algorithm which works like this permutateBuckets([A,B,C]) and gives the following result: [ [[A,B,C]], [[A,B],[C]], [[A,C],[B]], [[B,C],[A]], [[A],[B,C]], [[B],[A,C]], [[C],[A,B]], [[A],[B],[C]], [[A],[C],[B]], [[B],[A],[C]], [[B],[C],[A]], [[C],[A],[B]], [[C],[B],[A]] ] In general: The permutation for [1,2,...,n] should include any possible arrangements of 1 up to n buckets that contain the input values, order of values within buckets is not relevant (e.g. [1,2] equals [2

Permutations unrank

匆匆过客 提交于 2021-02-10 04:24:03
问题 I know of an algorithm (it can be found online) to rank a permutation, i.e. given a permutation return the integer index into the list of lexicographically-sorted permutations, but I don't know any unrank algorithm that does the opposite: given an index i, return the i-th permutation in that lexicographic order. Since I couldn't find any, can somebody please shed some light? 回答1: Let's say you are permutating the letters (a, b, c). There are 3×2×1=6 permutations. Out of these, a third starts

Permutations unrank

蹲街弑〆低调 提交于 2021-02-10 04:21:50
问题 I know of an algorithm (it can be found online) to rank a permutation, i.e. given a permutation return the integer index into the list of lexicographically-sorted permutations, but I don't know any unrank algorithm that does the opposite: given an index i, return the i-th permutation in that lexicographic order. Since I couldn't find any, can somebody please shed some light? 回答1: Let's say you are permutating the letters (a, b, c). There are 3×2×1=6 permutations. Out of these, a third starts

Permutations unrank

房东的猫 提交于 2021-02-10 04:18:31
问题 I know of an algorithm (it can be found online) to rank a permutation, i.e. given a permutation return the integer index into the list of lexicographically-sorted permutations, but I don't know any unrank algorithm that does the opposite: given an index i, return the i-th permutation in that lexicographic order. Since I couldn't find any, can somebody please shed some light? 回答1: Let's say you are permutating the letters (a, b, c). There are 3×2×1=6 permutations. Out of these, a third starts

Permute groups in a data.frame R

陌路散爱 提交于 2021-02-08 10:44:44
问题 I have a data.frame like this: DqStr <- "Group q Dq SD.Dq 1 -3.0 0.7351 0.0067 1 -2.5 0.6995 0.0078 1 -2.0 0.6538 0.0093 2 -3.0 0.7203 0.0081 2 -2.5 0.6829 0.0094 2 -2.0 0.6350 0.0112" Dq1 <- read.table(textConnection(DqStr), header=TRUE) I would like to randomize group membership but only for rows with the same value of Dq1$q g <-unique(Dq1$q) Dq2<- data.frame() for(n in g) { Dqq <- Dq1[Dq1$q==n,] Dqq$Group <-sample(Dqq$Group) Dq2 <- rbind(Dq2,Dqq) } That could also be done with plyr library

How To Make Permutation In Javascript?

久未见 提交于 2021-02-07 21:53:17
问题 I want to make permutation with javascript, this is my code const arr = [1, 2, 3, 4, 5]; for (let i1 = 0; i1 < arr.length; i1++) { for (let i2 = i1 + 1; i2 < arr.length; i2++) { console.log(arr[i1] + ' ' + arr[i2]); } } https://jsfiddle.net/op51x6mv/1/ result from that code: ["1 2", "1 3", "1 4", "1 5", "2 3", "2 4", "2 5", "3 4", "3 5", "4 5"] I want to ask, why are all the results from the permutation not displayed? From these results I did not see the numbers ["2 1", "3 1", "3 2", "4 1",

Find all permutations of values in Spark RDD; python

末鹿安然 提交于 2021-02-07 10:51:39
问题 I have a spark RDD (myData) that has been mapped as a list. The output of myData.collect() yields the following: ['x', 'y', 'z'] What operation can I perform on myData to map to or create a new RDD containing a list of all permutations of xyz? For example newData.collect() would output: ['xyz', 'xzy', 'zxy', 'zyx', 'yxz', 'yzx'] I've tried using variations of cartesian(myData), but as far as I can tell, the best that gives is different combinations of two-value pairs. 回答1: Doing this all in

Permutations with duplicates

萝らか妹 提交于 2021-02-07 07:35:21
问题 Before I start, I have to apologize for bringing up another case of permutations with duplicates. I have gone through most of the search results and can't really find what I am looking for. I have read about the Lexicographical order and have implemented it. For this question, I am suppose to implement a recursion method that prints out the all the strings of length n consisting of just the characters a and b that have an equal number of a and b’s. The strings must be printed out one line at

Generate equation with the result value closest to the requested one, have speed problems

淺唱寂寞╮ 提交于 2021-02-06 02:03:19
问题 I am writing some quiz game and need computer to solve 1 game in the quiz if players fail to solve it. Given data : List of 6 numbers to use, for example 4, 8, 6, 2, 15, 50. Targeted value, where 0 < value < 1000, for example 590. Available operations are division, addition, multiplication and division. Parentheses can be used. Generate mathematical expression which evaluation is equal, or as close as possible, to the target value. For example for numbers given above, expression could be : (6

Generate equation with the result value closest to the requested one, have speed problems

微笑、不失礼 提交于 2021-02-06 02:02:01
问题 I am writing some quiz game and need computer to solve 1 game in the quiz if players fail to solve it. Given data : List of 6 numbers to use, for example 4, 8, 6, 2, 15, 50. Targeted value, where 0 < value < 1000, for example 590. Available operations are division, addition, multiplication and division. Parentheses can be used. Generate mathematical expression which evaluation is equal, or as close as possible, to the target value. For example for numbers given above, expression could be : (6