# Tag Info

Accepted

### Efficient lazy weak compositions

Chunks of weak compositions Here is slightly modified version of algorithm used in Combinatorica`NextComposition converted to a ...
• 14.7k
Accepted

### Faster derangements?

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

### Permutations[Range[12]] 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 ...
• 5,921
Accepted

### Solving word search puzzles

Here we go... ...
• 68.8k

### Faster derangements?

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

...
• 349k

### Alternative to Subsets to generate k-combinations

Subsets function takes optional third argument with standard sequence specification. Using this third argument you can take subsets "in chunks". For example, ...
• 14.7k

### House of Santa Claus

This is of course the Chinese postman problem, which is solved by the function FindPostmanTour[]. First, represent the edges of the directed graph: ...
Accepted

### How to generate all Feynman diagrams with Mathematica?

Here is a piece of code that is inspired by quantum field theory. The physics background can be found in this physics.SE post. First, we define some auxiliary functions: ...

### Transform a number to a factorial

An example target, a bit over half-a-million digits: x = 123456!; IntegerLength@x 574965 Results for target, and a non-hit: ...
• 25.1k

### Improving speed of code computing number of nonrepeating partitions

Here is a summary of comments (before @ciao's best answer above), with a change in notation. These functions calculate the number of partitions of n into exactly <...
• 14.9k
Accepted

### Improving speed of code computing number of nonrepeating partitions

This seems pretty quick, particularly on larger cases / larger k, e.g. 451, 29, 101 finishes in a few seconds on the loungebook. N.B. - I have not tested this ...

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

### Lazy form of Tuples/Outer to loop over list of lists

The implementation of lazy tuples here pretty much contains the solution to the lazy Outer problem. I will take the relevant parts from that code. The following ...
• 112k
Accepted

### How to generate all possible orderless partitions of a list according to another list?

A solution using Repeated, ReplaceList, and the Orderless attribute. ...
• 264k

### 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 ...
• 264k

### Improving speed of code computing number of nonrepeating partitions

Here is a totally different approach based on the fact that successive products forming the generating function are due to multiplication by a binomial $1+t*z^j$. Form a matrix $v$ of zeros with $n+1$ ...
• 14.9k

### How to count all cliques (not just maximal ones) in graphs?

Mathematica only finds maximal cliques, i.e. cliques (complete subgraphs) that are not part of a larger clique. Computing the number of all cliques given the maximal ones is not trivial because some ...
• 225k
Accepted

...
• 64.5k
Accepted

### Generating Tuples with restrictions

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

### Mathematica implementation of Zeilberger's algorithm (previously done in Maple)

There is also a newer package, HolonomicFunctions, that has an implementation of Chyzak's generalization of Zeilberger's algorithm. To perform the desired task, use the following commands: ...

### How to generate all possible orderless partitions of a list according to another list?

Permutations treats repeated elements as identical, so you can get a flattened version of the desired result with something like ...
• 83.4k
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}];
• 225k

### Transform a number to a factorial

Stirling's approximation, $n! \sim n^ne^{-n}$, is the Swiss army knife of factorial problems. If $x = n!$, this implies that $\ln x \sim n \ln n - n$; and surprisingly this can be solved with a ...
• 13.6k
Accepted

### Finding all sublists or substrings of a given list/string

TMTOWTDI applies to both of these problems. Below I present an overview of various approaches I've come across, followed by timing data obtained in 10.4 on Windows 10 (the timing code is available as ...
• 8,564

### generating integer partitions

I needed to do this sometime ago while investigating Bell polynomial analogs. Normally, you'd do FrobeniusSolve[Range[n], n] but the fastest variation (and quite ...

### Solving word search puzzles

Update To allow string with multiple words separated by single space, and possible multiple instances of word and non empty intersection of positions: ...
• 55.1k

### Permutations of lists of fixed even numbers

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