# Questions tagged [permutation]

1825 questions

1

50

Views

### Get all the possible combination of a string generated from ASCII character between two numbers

I need a simple javascript function which takes 3 inputs 1- Start ASCII value 2- End ASCII value 3- String length The function will loop from starting value to ending value until length has been made. For example, start - 65 end - 67 length- 2 I want all the combination (length 2) of ASCII of...
murtuza hussain

2

11.2k

Views

### Listing all permutations of a given set of values

I am interested in comparisons of different techniques/approaches one could use to generate all potential permutations of a given set.
Bober02

1

245

Views

### How to calculate all possible combinations of values to cover dynamic amount?

I am attempting to return all the possible unique combinations of ‘piping’ needed to at least cover the amount of feet provided. This problem is similar to common coin change algorithms. Pipes come in increments of 10', 25', and 50'. I’ve looked at examples from here and here which seem to be...
Matthew Moran

1

76

Views

### How to find the value of k after the following pseudocode has been executed?

What is the value of k after the following pseudocode has been executed? k := 0 for i1 := 1 to n1 k := k + 1 for i2 := 1 to n2 k := k + 1 ... for im := 1 to nm k := k + 1
CakeWalkCode

0

56

Views

### All permutations of a string with repetitions allowed

This is my recursive solution which returns a set of all permutations of a string. However, this implementation does not allow any repetitions. For instance for the input string rs, it will output only {rs,sr} whereas with repetitions allowed the correct output should be {rs,sr,rr,ss}. Can the same...
jaywalker

1

99

Views

### All permutations in range with parameters

I am trying to find efficient algorithm to solve the following problem. Give a range of numbers from 1..N, and some arbitrary numbers K and M, find all possible permutation in given range. Where K represents the number of elements and M represents a minimum distance between elements. So let's look...
hasskell

2

73

Views

### RegEx that matches only if a string contains a word from each list

I'm developing a software that has to check if a text contains a word taken from a specified list and a word taken from another specified list. Example: list 1: dog, cat list 2: house, tree the following texts has to match: the dog is in the house -> contains dog and house my house is full of dogs -...
Vpiff

0

254

Views

### Java permutation of String array

I am trying to find all possible options of combining a string array with two elements. Let's say, the array has two elements {'we','are'}. The output should be:'we' 'are' 'we are' 'are we' I could manage, with some search, to put together this code: public class Main { public static void main(Strin...
Gexo

0

74

Views

### Black-box combinatorial optimization over permutations

I am solving general black-box optimization problems like: x*: f(x) -> min, where x are permutations of length N (N = 50 for example, so brute force search is not possible). Objective function f(x) is represented by stand-alone computer code and x represents configuration of complex system with the...
michal

1

30

Views

### permutation for string doesnt work for array of ints

So I have the working string perm code below public static List myperm( String s ){ List l = new ArrayList(); mypermImpl('', s, l ); return l; } public static void mypermImpl( String built, String other, List l ){ if (other.length() == 0 ){ l.add( built ); } for ( int i=0; i
Joe Bloom

1

99

Views

### How to generate all possible X sets of matchups for N teams split into N/2 pairs?

I wasn't sure how to word this question... Any suggestions or edits would be appreciated! I am trying to get all possibilities for a league schedule. I have 8 teams that are playing against each other for 12 weeks. Each week there are four time slots at which one pair of teams would play. How to spl...
Abraham

2

55

Views

### plsql - permutation update

I'd like to anonymise names in a large table. For this I'd like to permute this names. How can I do this? I tried the following update ( select t.id, t.name, t.nr, r.id, r.name, r.nr from (select id, name, rownum nr from person) T inner join (select id, name, rownum nr from (select id, name from per...
user1753180

0

115

Views

### LeetCode - Check if Given 4 ints can make 24

I am attempting this LeetCode question, which asks to right a boolean function that returns true if the given array of 4 ints can make 24 through the basic arithmetic operators +,-,/,*. The parentheses don't matter because they will be implicitly accounted for if all permutations are correct. For th...

1

329

Views

### C++ Backtracking permutations

I'm trying to print all permutations of the set {1, 2, ...N}, without success. I've tried to implement it via backtracking. When I add an element to the permutation, I check if it doesn't already exist in it, then I check if it's a solution (if there are N numbers in the permutation), then print it....
N. Nae

0

56

Views

### Analysis of algorithm for permutation generation

I've been trying to get around for the analysis of this C++ program for permutation generation. I know in the algorithm that the time complexity is O(n*n!) and O(n) because it requires it to print a permutation. Can someone further explain the analysis of the implementation below? // permutation ge...
RyanP

1

106

Views

### Largest Permutation in k steps (R)

I have a problem where I would like to replace 2 numbers in a set upto 'k'-times such that each time they are switched, I get the largest possible permutation and print this after k-swaps. For example with k=2, for the set (1,4,2,5,3,3) in 1 step I would swap (1,5) to create (5,4,2,1,3,3). In step...
Tony Hellmuth

0

13

Views

### How to display an entire tuple, list, and/or string with certain elements in a user defined index?

I've been trying to force python to display anything from strings, lists, tuples, etc if said string contains certain elements in a certain index. For example, let's say I need to find the string with X amount of elements in its known indexes. At the minimum one of these strings has the elements in...
Travis Wells

0

47

Views

### Generate all possible combinations of certain string with placeholders and a set of words

I have 3 datasets which are : patterns=[ '[foo] is a [bar]', '[foo] is not a [bar]', '[foo] could be a [bar]' ] fooSet=[ 'a','b', 'c' ] barSet = [ 'd', 'e', 'f' ] these data sets will be dynamic, it could be 5 different patterns and 4 data sets, I have already tried with lodash each and various loop...
Vargas Rickky

1

107

Views

### Creating permutations from columns in dataframe

Hi I have a dataframe as follows: And would like to create a dataframe with 2 columns: Writer1 Writer2 that lists all the permutations of writers of a song ex: for the song 03 Bonnie & Clyde the writers: Prince, Tupac Shakur, Jay-Z, Tyrone Wrice and Kanye West were involved. My dataframe therefore s...
joe borg

1

71

Views

### Finding possible permutations for range of values with changing parameters

Possible ranges with assigned actions: if(val == middle) Run() 2. if(val > middle && val < top1) Run() 3. if(val >= top1 && val < top2) PickWeapon() 4. if(val >= top2) Jump() 5. if(val < middle && val > bottom1) Run() 6. if(val bottom2) DropWeapon() 7. if(val middle && val < top1) { Run(); } else...
Code Hooligan

0

69

Views

### Generating symmetric permutations

I have a list of different combinations of letters of the alphabet {{'a'}, {'b'}, {'c'}, {'a', 'b'}, {'a', 'c'}, {'b', 'c'}} There is no pattern to them - that isn't important to this problem. Let's call a permutation of this list symmetric if they are the same under substitution, i.e. you can get f...
NMister

3

64

Views

### Unexpected results when using recursion

I've just started to get into the world of python and frankly, I'm a little bit confused about the results the following implementation gives me. It's just a recursive function that should output all of the permutations of a given list. I know there's probably a thousand better ways of doing the sam...
nachosanchez

1

63

Views

### What is the purpose of “undoing” steps after a recursive call (JAVA)?

This is a snippet to create all possible permutations of an integer array. I would specifically like to know the purpose of the line when the last element is removed from the tempList. I have tried to add print statements everywhere, but I am still not conceptually understanding the recursive backtr...
Days

0

76

Views

### Optimizing permutation generation

I'm working on an app in which, give an array of colors (exadecimal values) it generate all the possibile permutation of that array; in order to shuffle the colors; demo: https://d2hxezalm5sz4p.cloudfront.net/ so when the grandient component is load a function setPermutation is fired: class Gradient...

1

54

Views

### Compare letters permutations to dictionary C

I've been trying to work on a program that outputs only the existing words of all the possible permutations of n letters, for example: Input 'eta' Output 'tea, eat, ate' As you can notice i don't want all the other permutations that are not words, such as 'aet, tae' For this purpose i have a diction...
Bruno Lo Faro

0

37

Views

### conditional permutation of strings

I am trying to print arrangement of numbers with following conditions The number at the ith position is divisible by i. i is divisible by the number at the ith position. def permutation(lst): if len(lst) == 0: return [] if len(lst) == 1: return [lst] l = [] for i in range(len(lst)): m = lst[i] if m...
Rohit

0

52

Views

### excel permutations, 5 or 6 slots, no repeating values, hitting row limit

my data set is Col A,B,D,E,F are '-1'- '-22' (without '-5', 21 values) and Col C is '-1'- '-22' So I found a bit of code to generate all possible combinations of however many columns of whatever length. Which was fine until I got to the 5 slot / 6 slot combinations I was working on. I have a separat...
Alberto Brown

1

70

Views

### Possible numbers with each digit value range given

We are given 3 variables, d, a and b. d specifies the maximum number of places. a and b specify the minimum digit and maximum digit respectively. We have to find how many numbers can be made each of which has its digits in non-decreasing order, with maximum d places, and each digit between a and b,...
Nisha

1

57

Views

### How to build permutation with some conditions in R [duplicate]

This question already has an answer here: mixed combinations / permutations from different sets 1 answer I am new to R and I am a little confused. Suppose I have a vector of c(1,2,3,4,5,6). I would like to generate permutations with four elements and every permutation should involve 1 and 5. Thank...
Bsides

1

48

Views

### Generate Permutations of a large number( probably 30) with constraints

I have list of numbers ( 1 to 30 ) most probably. I need to arrange the list in such a way that the absolute difference between two successive elements is not more than 2 or 3 or 4, and the sum of absolute differences of all the successive elements is minimum. I tried generating all possible permuta...
Veer Bhansari

1

117

Views

### Generate all permutations of 128bits as bytes or bits, not as strings

I was trying to generate all the permutations of 128 bits and store them in some kind of structure. I found some useful information about it in other Stack Overflow questions using: keys = map(''.join,itertools.product('01',repeat=n)) The problem is that this solution is useful only for enough sma...
victor

3

25

Views

### Permutate removal of defined substrings with varying length from strings

I am trying to generate all permutations from a list of strings where certain substrings of characters are removed. I have a list of certain chemical compositions and I want all compositions resulting from that list where one of those elements is removed. A short excerpt of this list looks like this...
And

2

136

Views

### Calculate large number of permutations in R

I have 2 large dataframes in R, both with circa 100k rows, which hold lists of geo coordinates (lat/ long). I am looking to iterate across them getting all combinations between items and thereafter, applying a function to it. Because the number of combinations is around 11 billion (11 x 1.000.000.00...
Jo Costa

1

61

Views

### Conditional combinations matrixes in r

How can I create all binary combinations of matrices with the condition that there can only be a single 1 per column and row. The example will clarify. This particular example must have 6 matrices of combinations, I am showing only the first 2. c1
Alfredo_MF

0

30

Views

### generate permutation from partition of numeric

i will generate permutations of a partitions. i generate partitions with this code: library(partitions) x
antonio nuzzo

1

97

Views

### Permutations of NxN matrix with equal summation of any row elements or column elements (N being odd number)

The matrix NxN has N rows and columns. It has all unique elements starting from 1 to (N^2). The condition is the summation of any row elements should be equal to summation of any other row or column elements. Example: For 3x3 matrix, one of the possible combination looks like following. 4 8 3 2 6...
Patrick

1

76

Views

### permutation in a list with repetition ocaml

I have a function that makes combinations of K distinct objects chosen from the N elements of a list, the problem is doesn't permute with repetition, for example: extract 2 ['a';'b';'c';'d'];; - : string list list = [['a'; 'b']; ['a'; 'c']; ['a'; 'd']; ['b'; 'c']; ['b'; 'd']; ['c'; 'd']] Here is my...
Toshiconzas

1

111

Views

### Python OOM error while shuffling itertools.permutation(range(15))

Of the 15! possible permutations of the digits 1-15, I need to select 10! of them at random. Unfortunately, while the approach in this answer avoids the out-of-memory issue encountered when storing all of the permutations and shuffling them, if I iterate over the first 10! permutations using the it...
Danny

1

29

Views

### SymPy Permutation groups parity not working as expected

I've implemented a Rubik's cube using permutations of Tuples. The cube with no changes is represented as (0, 1, 2, ... , 45, 46, 47). To apply a 'turn' to the cube the numbers are shuffled around. I've pretty fully tested all of my turns to the point that I'm fairly sure that there is no typos. I'v...
elliot_martin18

1

19

Views

### trouble generating permutations

I'm trying to generate permutations given an array of distinct integers in Java, can't figure out what's wrong with my solution. I know there are hundreds of solutions online for this, but I'm trying to do it using a specific approach that makes sense to me (rather than trying to memorize someone el...