# Tag Info

Accepted

### Optimization of function taking a permutation

How about a Monte-Carlo-Metropolis search? I'll implement a simplistic version here. See complete universal code further down. Update: Cleaned-up code now available in the Wolfram Function Repository, ...
• 47.9k
Accepted

### Faster derangements?

Chunks of derangements Since I've already written library link code generating permutations, generating derangements requires just few tweaks: ...
• 15.1k

### Faster derangements?

This is the fastest method I have come up with: ...
• 272k

### Fastest way to generate {{a,a},{a,b},{a,c},{b,b},{b,c},{c,c}} from {a,b,c}

Select[Tuples[{a,b,c},2],OrderedQ]
• 28.9k

### Faster derangements?

Here is one way to generate them directly: it is based on a way to generate all permutations but discards invalid ones early: ...
• 8,774
Accepted

### Delete duplicates from list of lists as if on a necklace

A high-performance solution Since you are planning to work with thousands of necklaces, it may be much faster to introduce a canonical form. The main point is to write a necklace canonization ...
• 7,836

### Permutations of nested parentheses (Dyck words)

StringReplaceList I just realized that there is a comparatively clean though not highly efficient way to write this using ...
• 272k

### Terse Method to Swap Lowest for Highest?

How about: Module[{tmp = test}, With[{ord=Ordering[tmp]}, tmp[[ord]] = Reverse @ tmp[[ord]]]; tmp ] {56, 9, 4, 3, -5, -2, -3, 1, 2, 7, 60, 58, ...
• 131k
Accepted

### StringContainsQ, but anywhere in order

StringMatchQ["aabbc", "*a*c*"] True StringMatchQ["aabbc", "*b*a*"] False You can also use ...
• 396k
Accepted

### Fastest way to generate {{a,a},{a,b},{a,c},{b,b},{b,c},{c,c}} from {a,b,c}

GroupTheoryToolsMultisets[{a, b, c}, 2] {{a,a},{a,b},{a,c},{b,b},{b,c},{c,c}}
• 26.8k
Accepted

### ls Ordering[Ordering[list]] optimal?

No, Ordering[Ordering[list]] not optimal. And yes, there is a faster method: ...
Accepted

### List all possible license plate numbers

I would use a = Alphabet[]; (* letter *) d = Range[0, 9]; (* digit *) result = Tuples[{a, a, d, d, d, d}];
• 235k

### Permutations of lists of fixed even numbers

The permutation you described is called "derangement". There is a function Derangement in Combinatoricapackage. ...
• 7,921
Accepted

### Permutations of lists of fixed even numbers

Permutations where no element remains in its original place are called derangements. Counting them is easy enough: the number of derangements of a set of size $n$ is $!n$, or the subfactorial of $n$. ...
• 8,774

### StringContainsQ, but anywhere in order

Is this what you need? StringContainsQ["aabbc","a" ~~ ___ ~~ "c"] True The following documentation pages should help you get going with string patterns in ...
• 23.6k
Accepted

### Number by permutation

Just a note - any method generating the permutations and the searching will get very slow very quickly, and blow RAM soon after. Something like this s/b much more efficient (e.g., on my goof-top, for ...
• 25.8k
Accepted

### Cyclic and Non-cyclic Permutations

Per the request, I post my comment as an answer: First question cy := Permute[#, CyclicGroup[Length@#]] & cy[Range@5] {{1, 2, 3, 4, 5}, {2, 3, 4, 5, 1}, {3, 4,...
• 26.8k

### Delete duplicates from list of lists as if on a necklace

Preface If one could create a function f that calculates a canonical form of a necklace that turns all equivalent necklaces ...
• 113k
Accepted

...
• 47.9k
Accepted

### Evaluating Pfaffian

In the answer to: "https://mathematica.stackexchange.com/questions/125794/compute-numeric-pfaffians-of-matrices-efficiently" there is a pointer to the code below. I hope this will be helpful....
• 52.6k
Accepted

### Connectivity in a molecule and permutations

Getting the graph from the XYZ file You have only a set of coordinates and atom types in an XYZ file. When you import it in Mathematica you can import 3 elements: the 3D plot, the coordinates, and ...
• 68.7k

### Faster derangements?

Here is a straightforward compiled implementation of Knuth's "Algorithm X" for lexicographically generating restricted permutations, specialized to the derangement case: ...
Accepted

### Can we turn this for loop into a more elegant Mathematica code?

Apparently, you try to apply a permutation given by list indirection to a vector duplicate. Here are several ways to do it, ...

### Fastest way to generate {{a,a},{a,b},{a,c},{b,b},{b,c},{c,c}} from {a,b,c}

Another possibility is to use Pick: ...
• 131k

### Permutations[Range[12]] produces an error instead of a list

Chunks of permutations Here is a LibraryFunction implementation of "CoolMulti" algorithm generating permutations of multisets. The algorithm is described in: A. ...
• 15.1k

...
• 396k
Accepted

### How to generate all involutive permutations?

I wondered how well Involutions has been implemented, so I tried to reimplement it myself. The following implementation can be up to 15 times faster than ...
Accepted

### How to represent a product of cycles in matrix form?

mat = {Sort @ #, #} & @ PermutationList[a]; MatrixForm @ mat // TeXForm \$ \left( \begin{array}{ccccccccccc} 1 & 2 & 3 & 4 & 5 & 6 & ...
• 396k
Accepted

### How do I get a list of all possible sums in a list nested list?

Total[Tuples@rn, {2}] should do. For cases where a very large number of tuples would be generated, ...
• 25.8k