Questions tagged [permutation]

1

votes
1

answer
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
-1

votes
0

answer
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
1

votes
0

answer
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

votes
1

answer
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

votes
1

answer
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
1

votes
0

answer
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
1

votes
3

answer
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

votes
1

answer
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
1

votes
0

answer
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

votes
1

answer
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
1

votes
0

answer
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
1

votes
0

answer
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

votes
1

answer
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

votes
1

answer
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

votes
1

answer
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

votes
1

answer
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
2

votes
3

answer
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
1

votes
2

answer
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

votes
1

answer
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
1

votes
0

answer
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

votes
1

answer
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

votes
1

answer
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

votes
1

answer
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

votes
1

answer
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

votes
1

answer
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...
stickersskeletal
1

votes
1

answer
75

Views

Permutation of two “linked” lists in python

Wondering if there is a way to use itertools.permutations() (or something else or similar) on two lists and in a way link the output of both so there is a one-to-one mapping between their outputs. Example: I have a byte x = 0xE3, x_bit = BitArray(x).bin = 11100011 that is the result of a specific or...
ritualmagick
1

votes
1

answer
49

Views

Numeric to alphanumeric encoder using python (permutation and regex)

Hello fellow stackers, I'm facing problem that I hope you can help resolve. I've written two pieces of code which I want to merge together. Basically on given input of an numeric string, I want to iterate over each character in the string. The characters are analysed by the conditional statement an...
Manifesto
1

votes
1

answer
41

Views

Heap's algorithm with permutation signature

I am making a code that can generate all the permutation of a list of elements and the signature of the permutation based on the original list. In general the number of permutations is given by the Stirling numbers of the first kind as a composition of k = n - C-cycles that partition the n elements....
user3671704
1

votes
1

answer
41

Views

Number of Node Insertion Sequences Which Create the Same BST?

I have a similar problem to this one. Given a certain insertion sequence which produces a BST, I need to count how many insertion sequences (including the one given) produce the same BST. The main difference is that my solution needs to allow for duplicate keys (I could only find solutions where al...
Sian
1

votes
2

answer
71

Views

R: Matrix Combination with specific number of values

I want to make all combinations of my Matrix. Ex. a binary 5 X 5 matrix where I only have two 1 rows (see below) Com 1: 1 1 0 0 0 1 1 0 0 0 1 1 0 0 0 1 1 0 0 0 1 1 0 0 0 Com 2: 1 0 1 0 0 1 1 0 0 0 1 1 0 0 0 1 1 0 0 0 1 1 0 0 0 . . . Com ?: 0 0 0 1 1 0 0 0 1 1 0 0...
JHKI
1

votes
0

answer
25

Views

Permutation with repetition of a list with variable list lentgh in Netlogo

i´m new to Netlogo as well as programming and struggling on the following problem: I need to implement a function Permu [k,n] in Netlogo where k is a list of elements e.g [1 2] while n is the length of the resulting list e.g. 3. The function should return all permutation say lists with length n whe...
geruter
1

votes
0

answer
14

Views

Perfect hashing for permutations

Consider the following list of permutations of {0,1,2,3,4,5,6,*,*,*} as generated with ordinary backtracking: Index Permutation 1. 0123456*** 2. 012345*6** 3. 012345**6* 4. 012345***6 5. 0123465*** ... 60480. ***6543210 Is it there an O(1) function which, for any permutation giv...
icecream notebook
1

votes
1

answer
27

Views

Is there a way to permute a subset of a matrix?

I'm working on a way to find the lowest 1-Norm of a given Matrix using a permutation of its rows. The problem is that the permutation can't be fully random. There are 4 subsets of rows in the Matrix having a special parameter. I want to permute just the rows having this one parameter and keeping tho...
E.J.K.
1

votes
1

answer
45

Views

permutations with repetition in python(to don t use set() or uniform() method )

I have a list like this: from itertools import permutations l = [1,1,1,1,1,1,1,2] The duplicate '1' entries in the original list mean that the distinct permutations only depend on where the '2' appears in the output; so there are only 8 distinct permutations. But the permutations() function will g...
Seyed Ali Aletaha
1

votes
1

answer
39

Views

Circular Primes Project Euler #35

This is the problem I'm trying to solve. The number, 197, is called a circular prime because all rotations of the digits: 197, 971, and 719, are themselves prime. There are thirteen such primes below 100: 2, 3, 5, 7, 11, 13, 17, 31, 37, 71, 73, 79, and 97. How many circular primes are there below on...
Riptide
1

votes
1

answer
44

Views

How do I iterate over all words up to permutations of the alphabet in Python?

This doesn't seem like such a niche problem to me, but I surprisingly can't find anything about it online. Suppose you have an alphabet set (for me the first m letters of the usual alphabet) and you want to efficiently iterate over all words of the alphabet (in order to do some analysis on them for...
Joel Brennan
1

votes
2

answer
1.7k

Views

Find the permutations where no element stays in place

I'm working with permutations where each element is different from its original location. I would like an algorithm that given {an input length, row and digit}, will give me the output number. Here's an example: If the input length is four, then all the permutations of 0123 are: 0123,0132,0213,023...
1

votes
5

answer
284

Views

Set combination question

Got this as an homework assignment and not really sure where to start! Given the set {1,2,3,4}, you can form six combinations of length two from that set, viz: {1,2},{1,3},{1,4},{2,3},{2,4},{3,4} If I was to choose one of the combinations, ({1,2} for example), how can I tell how many of the others...
MarkL
1

votes
5

answer
862

Views

Permutation of an arraylist objects

I have an arraylist which contains some objects and i have to get permutation of that objects?How can i do that? Suppose MyList is an arraylist which contains 4 objects. ArrayList myList = new ArrayList(); myList.Add(1); myList.Add(2); myList.Add(3); myList.Add(4); so arraylist count is 4 so i want...
Anjana
1

votes
2

answer
1k

Views

Objective C - Permutations Calculation of Duplicates

I can't seem to really think of a way to solve this one, can't get my brain around it for some reason. The problem I'm trying to solve is this: For a puzzle-solver type algorithm, I'm pulling the duplicate letters as a substring of an NSString. Let's say the user enters 'RBEEEIOOUUU' I'm pulling j...

View additional questions