# Tag Info

## New answers tagged combinatorics

0

There are short description and the definition of the Tableaux: Quiet@Needs["Combinatorica"]; ?? Tableaux Tableaux[p] constructs all tableaux having a shape given by integer partition p. Attributes[Tableaux] = {Protected} Tableaux[s_List] := Module[{t = LastLexicographicTableau[s]}, Table[t = NextTableau[t], {NumberOfTableaux[s]}]] ...

5

As a proof of concept, I present here a straightforward implementation of Don Knuth's "Algorithm L" for generating permutations in lexicographic order: cPermutations = Compile[{{list, _Integer, 1}}, Module[{n = Length[list], p = Sort[list], pbag, j, k}, pbag = InternalBag[Most[{1}]]; ...

7

The type of a permutation of length $n$ is $\{\lambda_1, \lambda_2, \ldots, \lambda_n\}$ where $\lambda_i$ is the number of cycles of length $i$. Therefore, the number of permutations of $\{1, 2, 3, 4, 5, 6\}$ that have two 1-cycles and two 2-cycles is NumberOfPermutationsByType[{2, 2, 0, 0, 0, 0}] (* 45 *) The best reference for Combinatorica is Steven ...

2

This is a great question, and surely a function that should be implemented in Mathematica already. To solve the problem, let us proceed in two phases: Compute the chromatic number $\chi(G)$ of the graph $G$. Iterate over all possible $\chi(G)$-colorings, and choose the first valid one. From this answer, we know how to compute the chromatic number: ...

11

RandomPartition[n_, p_] := Module[{r}, r = RandomSample[Range[n - 1], p - 1] // Sort; AppendTo[r, n]; Prepend[r // Differences, r[[1]]] ] RandomPartition[100, 16] (* {4, 1, 4, 3, 12, 5, 13, 3, 9, 8, 2, 2, 12, 11, 1, 10} *) RandomPartition[100, 16] // Total (* 100 *) Testing: And @@ Table[ n = RandomInteger[100000]; p = RandomInteger[{1, ...

Top 50 recent answers are included