# 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, ...
Accepted

### Faster derangements?

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

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

Since Mathematica 8 it is possible generate the elements of any group one by one with GroupElements. Here's for example a randomly chosen element of the permutation ...

### Faster derangements?

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

### 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]

### 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: ...
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 ...

### 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 ...

### 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, ...
Accepted

### StringContainsQ, but anywhere in order

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

### Generating Tuples with restrictions

Select[ IntegerPartitions[24, {8}, Range], #.# == 86 & ] ...
Accepted

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

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

### Check if two lists are equal in any order

Is it any permutation ? Then I think then this should do areListsEqual[List1_,List2_]:=(Sort[List1]===Sort[List2]);
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}];

### Permutations of lists of fixed even numbers

The permutation you described is called "derangement". There is a function Derangement in Combinatoricapackage. ...
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$. ...

### 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 ...
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}}
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 ...

### 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 ...
Accepted

...

### Check if two lists are equal in any order

If you have many duplicates (and the number of duplicates matter) then Tally can improve performance sufficiently ...
Accepted

### What is the fastest way to get the nth distinct permutation of a list?

A simple recursive function I've used many times: ...
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,...
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: ...

### Permutations on elements a>b && b>c

Subsets[Reverse@Range, {3}] {{5, 4, 3}, {5, 4, 2}, {5, 4, 1}, {5, 3, 2}, {5, 3, 1}, {5, 2, 1}, {4, 3, 2}, {4, 3, 1}, {4, 2, 1}, {3, 2, 1}} ...
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 ...