## Efficiently create derangement of a vector in R

I'm looking into a way of efficiently creating a derangement (and conversely specific permutations) of a vector in R. As far as I've seen, there's no base function that does that and also there's not much about it here on SO. An obvious start is sam...
more »

## Print all the permutation of vector

Let's design a clock. This clock has a format of (hour: miniutes). Lets use bit to represent it. For example, 10: 15 is represented as 1010:1111. Question: given n as total number of bit that is 1, print all the possible clock time. (eg, in th...
more »

How would one do the following in Haskell: Return all permutations of a list where one element comes before the another element (cannot assume that elements of the list can be ordered)? My solution was to do: sLeftOf l r lss = [ ls ...
more »

## Positional equality in haskell list

If I have two lists, I want to define a positional equality (in a particular sense) between elements. For example if: k = [[3,1,2,4],[1,4,2,3],[1,3,4,2]] s = [["a","b","c","d"],["d","a","c","b"],["c","b","a","d"],["d","b","c","a"]] and I want to b...
more »

## Finding even permutations using Haskell

I tried to figure out how to find the even permutations out of the set {permutations [1..n]}. I have asked this question before on a different forum, and got an answer that worked namely the code was: Import Data.List -- number of inversions in a p...
more »

## Counting all permutations of a string (Cracking the Coding Interview, Chapter VI - Example 12)

In Gayle Laakman's book "Cracking the Coding Interview", chapter VI (Big O), example 12, the problem states that given the following Java code for computing a string's permutations, it is required to compute the code's complexity public static void ...
more »

## Extreme slow-down when starting at second permutation

Consider the following code: #include <algorithm> #include <chrono> #include <iostream> #include <numeric> #include <vector> int main() { std::vector<int> v(12); std::iota(v.begin(), v.end(), 0); //s...
more »

## Conditions in a list comprehension , finding possibilities

there are 3 keys and 3 locks, and i have to write a code to show the possible tries. Rules are: Second key never can be placed before the first one. No keys can be tried more than once. First key cannot be placed as the first one. and you can't...
more »

## Specific element permutation within an array of characters in JAVA?

How can I list all uppercase/lowercase permutations for any letter specified in a character array? So, say I have an array of characters like so: ['h','e','l','l','o'] and I wanted print out possible combinations for say the letter 'l' so it would pr...
more »

## Permutations of a list containing the same element several times

I have to write a function that takes two numbers and does this: placeOneBlock 1 5 ["feeee", "efeee", "eefee", "eeefe", "eeeef"] So it makes every permutation of an m long list with n * "f"-s and m-n * "e"-s. If n > 1 than the "f"-s should stay in...
more »

## How to improve efficiency of algorithm which generates next lexicographic permutation?

It must be noted here that I performed the mathematics by hand on paper to derive the foregoing proofs. I am not sure if the proofs would have become apparent by solely using the medium of the modern computer. The definition of "efficiency" as used ...
more »

## Pandas: Pairwise concatenation of column vectors

I'm working with a frame like df = pd.DataFrame({ 'G1':[1.00,0.69,0.23,0.22,0.62], 'G2':[0.03,0.41,0.74,0.35,0.62], 'G3':[0.05,0.40,0.15,0.32,0.19], 'G4':[0.30,0.20,0.51,0.70,0.67], 'G5':[0.40,0.36,0.88,0.10,0.19] }) and I want to manipulate it so...
more »

## Provably correct permutation in less than O(n^2)

Written in Haskell, here is the data type that proves that one list is a permutation of another: data Belongs (x :: k) (ys :: [k]) (zs :: [k]) where BelongsHere :: Belongs x xs (x ': xs) BelongsThere :: Belongs x xs xys -> Belongs x (y ': xs)...
more »

## Algorithm to create subgroups of people

we are looking for an algorithm that could help us creating subgroups of people. I'll explain it better with an example: We have a group of 5 students, let's call them A, B, C, D, E. Given a number (call it n) smaller than the number of students (&l...
more »

## C Multiple arrays permutations algorithm

I'm trying to write a program that generates permutations upon a list of words stored into several arrays. For example, my program asks for 2 groups of words like this : words #1: abc def ghi words #2: 123 456 What i'm trying to have is this outp...
more »

## Algorithm - find all permutations of string a in string b

Say we have string a = "abc" string b = "abcdcabaabccbaa" Find location of all permutations of a in b. I am trying to find an effective algorithm for this. Pseudo code: sort string a // O(a loga) for windows of length a in b // O(b)? sort tha...
more »

## Permutation of a list with equals objects - Java

List<String> original = Lists.newArrayList("A", "B", "C"); Collection<List<String>> permutations= Collections2.orderedPermutations(original) gives [A, B, C] [A, C, B] [B, A, C] [B, C, A] [C, A, B] [C, B, A] Great, now I have a...
more »

## How to identify all possible permutations of a time series according to order of permutation

I am trying to figure out a way to translate a financial time series into a symbolic time series that account for all "meaningful" permutations according to a given order (in R): Example: Given a Time Series: ts= c(1,2,3,4,5) If Order=2 I would li...
more »

## Coefficient table does not have NA rows in rank-deficient fit; how to insert them?

library(lmPerm) x <- lmp(formula = a ~ b * c + d + e, data = df, perm = "Prob") summary(x) # truncated output, I can see `NA` rows here! #Coefficients: (1 not defined because of singularities) # Estimate Iter Pr(Prob) #b ...
more »

## Monte Carlo estimate of p-value for F-statistic in ANOVA based on permutation method

I am trying to do a permutation test for ANOVA on (y1,...,yN) with group identifiers g. I am supposed to be using (1)/(g-1) summation of (muhatj - muhat)^2 as the test statistic and muhatj is the jth group sample mean, and muhat=(1/g)summation muhatj...
more »

## All combinations to split a vector into two groups in R

I am trying to figure out an efficient way to obtain all unique combinations that elements in a vector (the vector is always a sequence between 1:n) can be split into two equal-sized groups. Each element in the vector must be represented once (in one...
more »

## How to add specific number of inversions to sorted array

Given a sorted array, is there a way to insert a specific number of inversions (at random locations)? At first I thought this would be straightforward, but then realized inversions can "undo" each other. Consider: starting with array: 2,4,6,8 one in...
more »