permutation

How to find every possible combination of arrays in PHP

♀尐吖头ヾ 提交于 2019-12-18 07:25:18
问题 $data = array( 'a' => array('a1', 'a2', 'a3'), 'b' => array('b1', 'b2', 'b3', 'b4'), 'c' => array('c1', 'c2', 'c3', 'c4', 'c5')); to get a1 a2 a3 b1 b2 b3 b4 c1 c2 c3 c4 c5 a1 b1 a1 b2 a1 b3 a1 b4 a1 c1 a1 c2 a1 c3 a1 c4 a1 c5 b1 c1 b1 c2 b1 c3 b1 c4 b1 c5 b2 c1 b2 c2 b2 c3 b2 c4 b2 c5 b3 c1 b3 c2 b3 c3 b3 c4 b3 c5 b4 c1 b4 c2 b4 c3 b4 c4 b4 c5 a1 b1 c1 a1 b1 c2 a1 b1 c3 a1 b1 c4 a1 b1 c5 a1 b2 c1 a1 b2 c2 a1 b2 c3 a1 b2 c4 a1 b2 c5 a1 b3 c1 a1 b3 c2 a1 b3 c3 a1 b3 c4 a1 b3 c5 a1 b4 c1 a1 b4

How to find every possible combination of arrays in PHP

蓝咒 提交于 2019-12-18 07:25:14
问题 $data = array( 'a' => array('a1', 'a2', 'a3'), 'b' => array('b1', 'b2', 'b3', 'b4'), 'c' => array('c1', 'c2', 'c3', 'c4', 'c5')); to get a1 a2 a3 b1 b2 b3 b4 c1 c2 c3 c4 c5 a1 b1 a1 b2 a1 b3 a1 b4 a1 c1 a1 c2 a1 c3 a1 c4 a1 c5 b1 c1 b1 c2 b1 c3 b1 c4 b1 c5 b2 c1 b2 c2 b2 c3 b2 c4 b2 c5 b3 c1 b3 c2 b3 c3 b3 c4 b3 c5 b4 c1 b4 c2 b4 c3 b4 c4 b4 c5 a1 b1 c1 a1 b1 c2 a1 b1 c3 a1 b1 c4 a1 b1 c5 a1 b2 c1 a1 b2 c2 a1 b2 c3 a1 b2 c4 a1 b2 c5 a1 b3 c1 a1 b3 c2 a1 b3 c3 a1 b3 c4 a1 b3 c5 a1 b4 c1 a1 b4

Generating permutations of a list in NetLogo

会有一股神秘感。 提交于 2019-12-18 06:59:36
问题 I'm trying to generate a list in NetLogo that contains several different unique lists of numbers 0 through n. For example, I have this line of code set mylists [[0 1 2] [0 2 1] [1 0 2] [1 2 0] [2 0 1] [2 1 0]] that I wrote to make all possible unique combinations of 0 1 and 2 without any repetition of the numbers within the lists. I would like to be able to the same thing but with a larger n. Is there an example of how to do this, or some sort of pseudocode algorithm that anyone knows of that

Computing the Factoradic Rank of a Permutation (N choose K)

可紊 提交于 2019-12-18 05:12:50
问题 I've recently learnt about CNS and FNS, and since they look so elegant to me, I decided to try and implement methods to generate combinations and permutations using those techniques. I finished my method to convert from n choose k combinations to a CSN rank and vice-versa but I'm banging my head against the wall trying to do the same with n choose k (unique) permutations. Thanks to @Joshua I got the unranking (FNS to permutation) method working: function Pr_Unrank($n, $k, $rank) { // rank

Generating All Permutations of Character Combinations when # of arrays and length of each array are unknown

ぐ巨炮叔叔 提交于 2019-12-18 04:15:01
问题 I'm not sure how to ask my question in a succinct way, so I'll start with examples and expand from there. I am working with VBA, but I think this problem is non language specific and would only require a bright mind that can provide a pseudo code framework. Thanks in advance for the help! Example: I have 3 Character Arrays Like So: Arr_1 = [X,Y,Z] Arr_2 = [A,B] Arr_3 = [1,2,3,4] I would like to generate ALL possible permutations of the character arrays like so: XA1 XA2 XA3 XA4 XB1 XB2 XB3 XB4

Generate all permutations of all lengths

青春壹個敷衍的年華 提交于 2019-12-18 03:35:34
问题 How would you generate all the possible permutations of list b(1,6,8,3,9,5) including ones of different length? Example: List a = [1,2,3] generateperms(a) 1,2,3 3,1,2 3,2,1 1,3,2 2,1,3 2,3,1 2,3 1,2 1,3 2,1 3,2 3,1 And so forth and getting all the permutarions of each length? EDIT: I'm just going to use this, written in python, works well enough: import itertools a = ['a','b','c'] for i in range(len(a)): print list(itertools.permutations(a,i+1)) 回答1: I think that would be all permutations of

Combinations and Permutations in F#

懵懂的女人 提交于 2019-12-17 22:35:03
问题 I've recently written the following combinations and permutations functions for an F# project, but I'm quite aware they're far from optimised. /// Rotates a list by one place forward. let rotate lst = List.tail lst @ [List.head lst] /// Gets all rotations of a list. let getRotations lst = let rec getAll lst i = if i = 0 then [] else lst :: (getAll (rotate lst) (i - 1)) getAll lst (List.length lst) /// Gets all permutations (without repetition) of specified length from a list. let rec getPerms

Heap's algorithm permutation generator

蹲街弑〆低调 提交于 2019-12-17 21:56:59
问题 I need to iterate over permutations of a tuple of integers. The order has to be generated by swapping a pair of elements at each step. I found the Wikipedia article (http://en.wikipedia.org/wiki/Heap%27s_algorithm) for Heap's algorithm, which is supposed to do this. The pseudocode is: procedure generate(n : integer, A : array of any): if n = 1 then output(A) else for i := 1; i ≤ n; i += 1 do generate(n - 1, A) if n is odd then j ← 1 else j ← i swap(A[j], A[n]) I tried to write a generator for

Iteratively generating a permutation of natural numbers

早过忘川 提交于 2019-12-17 19:59:50
问题 I have a somewhat unusual question, that may or may not have been asked before (I did not find anything though, however I might just have looked for the wrong buzzwords). My task is pretty simple: Given the "list" of natural numbers up to an N [0, 1, 2, ... N - 1] I want to shuffle this sequence. E.g. when I input the number 4, one possible result would be [3, 0, 1, 2]. The randomness should be determinable by some seed (which however is standard to most PRNGs in common languages). The naive

javascript permutation generator with permutation length parameter

岁酱吖の 提交于 2019-12-17 18:48:53
问题 I've seen a few generators out there but they all make a squared matrix. For example, you give it a list of three items and it'll assume the output of the length is also three. However, I'd like to specify the items and the length. Sound like an easy problem can't believe there isn't a library available for it. Would like to avoid writing this myself if there's a tested library out there. Any suggestions would be great. Example of what i've found var list = 'abc'; perms = permutations(list);