Questions tagged [combinatorics]

Questions on the use of Mathematica in combinatorics, including the Combinatorica add-on package.

Filter by
Sorted by
Tagged with
1
vote
1answer
64 views

Randomsample without repetition

I'm looking for a simple way to generate random samples of lists of integers such that each time I sample I'm sure it chooses a new random sample. This is closely related to Picking random items out ...
3
votes
1answer
67 views

Compute all trees on a given label set

Given a set of labels {a_1,...,a_n} (with some labels possibly appearing multiple times) I would like to efficiently compute all trees with n leaves labelled {a_1,...,a_n} and 2n-2 nodes. This is ...
0
votes
0answers
36 views

Climbing/Descending the Multidimensional Integer Ladder

This is basically a follow-up to Climbing/Descending the Integer Ladder, but in multiple dimensions. It's basically just an index counting problem, but combinatoric blow-up makes it interesting. In ...
2
votes
2answers
67 views

Overlay Graph3D with Graphics, with aligned coordinates

I have a Graph3D object representing a 3D lattice path ...
4
votes
1answer
333 views

How to perform a reduced knapsack problem

I have a problem statement that seems to be a reduced version of the knapsack problem, but I don't know how do it in Mathematica. The problem is as follows: Given a set, S, of integers (e.g {a,b,c,...}...
3
votes
2answers
69 views

using DeleteCases with CoprimeQ

first let me show what I have working correctly f = Permutations[Range[5], {3}] Riffle[f, Apply[CoprimeQ, f, {1}]] now I would like to automate the deletion of a ...
8
votes
4answers
485 views

Climbing/Descending the Integer Ladder

A fun combinatoric puzzle that's popped up in my work that I think would be cute to have a Mathematica solution to, if anyone wants to give it a go. It's basically a ladder climbing/descending problem ...
1
vote
1answer
39 views

Number of partitions of an integer with a fixed number of parts

Is there an easy way in Mathematica to find the number of partitions of $n$ into $k$ parts? Or equivalently, the number of partitions of $n$ with largest part equal to $k$? I realize the function ...
1
vote
2answers
79 views

Solving 190 equations from a list of 2x20 elements [closed]

I have a list of 20 pairs of elements, say {{x1, y1}, {x2, y2}, ...}, and I want to solve the following equation for a constant c...
4
votes
1answer
113 views

Visualizing set partition lattice

There's a cool visualization of set of all partition over 4 elements ordered by refinement, which makes it a lattice. Can Mathematica be used to generate these kinds of visualizations automatically? ...
0
votes
1answer
81 views

From a bag of n balls, with c colours, and d draws count how many variations are possible? [closed]

First, the objective is not to use formulas for combinations, or permutations. The objective is to use loops(for, while, etc.) to make Mathematica count the number of possible variations/sequences of ...
4
votes
4answers
196 views

Generating all symmetric binary matrices of order up to 7?

I want to create all symmetric binary matrix with order up to 7. Can anybody help in creating this? I want to obtain the subset of all symmetric matrices, with all diagonal entries being zero.
9
votes
2answers
236 views

Solving a rotating combination lock puzzle

The following puzzle appears in The House of da Vinci II and I thought it might be interesting to tackle in Mathematica: There are numbers marked on four rotating cylinders. These numbers must add up ...
3
votes
1answer
62 views

Counting terms in recursive operation

Suppose $X$ is an algebra and $T :X\to X$ is linear function. Let $L:X\to X$ be a function satisfying the following property $$L(a \cdot b)= T(a)\cdot b + a \cdot T(b)+b\cdot T(a)+T(b)\cdot a\tag{*}$$...
4
votes
2answers
151 views

Non crossing set partitions

A set partition is noncrossing if whenever four elements $a<b<c<d$ are such that $a,c$ are in the same block and $b,d$ are in the same block then $a,b,c,d$ are all in the same block. Can I ...
2
votes
2answers
71 views

How to program combinatorics problems about randomly moving cards from $A$ to $B$ to $C$ to $A$?

I have a lot of problems with the following scenario, for example, Given 3 boxes $A$, $B$ and $C$. The box $A$ contains 2 identical cards $x$, 4 identical cards $y$ and 1 card $z$. The box $B$ ...
2
votes
1answer
91 views

How to find formula from a table?

I recently started using mathematica for simple tasks like simplifying etc. First of all let me say if this breaks any rules I apologize since I'm a novice in using this and I'll remove the question. ...
8
votes
2answers
367 views

How to remove any words containing two adjacent characters with different in both cases and letters?

I have a list of permutations of ABCabc and I want to remove any permutations with two adjacent characters with different in both cases (uppercase and lowercase) ...
7
votes
2answers
229 views

List of tuples without duplicates & repeated values [duplicate]

Given some number nand set of values vals, I want to obtain all the tuples/permutations of size ...
3
votes
2answers
132 views

How to check whether a string contains a certain number of consonants and vowels?

I am trying to check the answer of the following problem programmatically. A manual calculation by hand must be possible but it is not my question. Given a string ...
9
votes
2answers
324 views

Lozenge tilings

I am trying to produce these lozenge tilings as a way of encoding plane partitions. I need to produce something like: but am using demonstration code like this: ...
0
votes
3answers
83 views

How to find the closed loop number of an array [closed]

I want to find the minimum number of swaps required to reset an array. This problem has many applications in linear algebra. The key point of this question is to find the number of closed loops in ...
5
votes
4answers
226 views

How to express permutation as the least number of exchanges

If there are grammatical or terminological errors in the following description, please help correct: In some problems, it is necessary to find out what minimum number of exchanges can change a list ...
2
votes
0answers
86 views

Why Does Subsets[…,{n}] not Output a Packed List, Even Though it Doesn't Unpack?

Assume list is packed. I expect Subsets[] is a structural operation because it depends on the number of elements, not on what ...
7
votes
2answers
81 views

Finding the best-fitting subsets by frequencies of list item groupings

Suppose I have a list of groups: {{1,2,3,4}, {1,2}, {3,4}} In this example, 1 most commonly appears within a group that contains ...
4
votes
1answer
53 views

How to list all possible 3-tuples with entries of the 3 tuples from 2 different sets?

If there are two sets $A={1,2,3,4}$ and $B={5,6,7,8}$, how to construct list of all possible 3 tuples where the first two entries are any element from set $A$ and the 3rd entry is any element from set ...
1
vote
1answer
37 views

$q$-multinomial series

I have the following code, which produces a $q$-multinomial coefficient, but selected randomly according to a Poisson distribution. Consider a 3D lattice path selected uniformly at random from a ...
0
votes
1answer
39 views

Optimisation Problem over binomial coefficients

I have 4 variables. $A= l{nq\choose l} {n(1-q)\choose n(1-q)-np+l}$ $B=(np-l){nq\choose l} {n(1-q)\choose n(1-q)-np+l}$ $C=(nq-l){nq\choose l} {n(1-q)\choose n(1-q)-np+l}$ $D=(n(1-q)-np+l){nq\choose l}...
7
votes
5answers
277 views

Rewriting partitions using exponents

I'm looking for a way to re-express a partition given in full form, like $\{{2, 2, 1, 1}\}$, into the shortened form $\{2^2, 1^2\}$, i.e. given a partition with repeated entries, count the number of ...
0
votes
2answers
106 views

How to calculate and display circuits, closed paths, simple paths, cycles … of edges (with a specific length)

I'd like to know that how can I find circuit(basic), simple path, closed path of these edges: Example: ...
3
votes
2answers
158 views

Permutations with Repetition Symbol

I am trying to compute this formula in Mathematica: $$ a = \sum_{n=0}^A P_A^{A-n,n} $$ Where A can be any positive number The problem is that I am unable to find the symbol for permutations with ...
2
votes
1answer
71 views

Visualization and setting up the Kneser graph of the number of combinations “a from n by k” in Mathematica

I need to visualize the combination "a from n to k" using a graph $KG_{n,k}$ and depict the following: As we know, the graph structure is determined by the number of vertices and the connection ...
2
votes
2answers
139 views

Counting the number of binary strings of length m with no consecutive 1s (RR). How to improve it?

I am new to Mathematica and I am trying to solve this problem of counting the number of binary strings of a certain length m, as far as no consecutive 1s are there. For instance m = 3, my recurrence ...
4
votes
3answers
159 views

All combinations assuming independence

This may be a basic question. Given an array of probabilities of length $n$, trying to create a vector of all $2^n$ combinations assuming independence between them, where either $p_i$ or $1-p_i$ is ...
3
votes
1answer
43 views

Find all pairs of disjoint subsets of list

Given a set $E$, how can I find all pairs of subsets $E_1, E_2$ which are non empty and disjoint? I don't care the order of $E_1, E_2$. Right now I use a bit complicated code. First find all ...
4
votes
2answers
524 views

How to solve this problem 710 of Project-Euler

I want to solve this problem: The number 6 can be written as a palindromic sum in exactly eight different ways: (1,1,1,1,1,1),(1,1,2,1,1),(1,2,2,1),(1,4,1),(2,1,1,2),(2,2,2),(3,3),(6) We shall define ...
5
votes
3answers
203 views

Combinations to crack code

I have a set of numbers from 0 to 9 numbers=Range[0,9,1] I want to determine the combination of three numbers between 0 and 9. There is a correct combination ...
4
votes
3answers
83 views

every set intersection for every set in a family with another family of sets

I want to find for each list within a list of lists what intersections occur when taking set intersection for each list in another list of lists. Hopefully that makes sense. I have tried ...
12
votes
7answers
645 views

Generate only unique combinations when input contains duplicates

I have a list with repeated elements, such as list = {a, a, b, c, c, c} and I'd like a list of the unique ways to choose 3 elements from it: ...
4
votes
1answer
83 views

Generate all spanning trees of the complete graph

How can you use Mathematica to generate all the spanning trees of the complete graph? One can count the spanning trees of a connected graph ${G}$ using e.g. the Tutte polynomial $T_{G}(1,1)$. For the ...
2
votes
1answer
53 views

Add Edge Label to certain edge in a bipartite graph

From https://mathematica.stackexchange.com/a/109436/70384 , I modified the code to display the bipartite graph I want and how do I label my edge with the edge weight by manually specifying it? I use <...
0
votes
1answer
85 views

How can I make a list of 3-connected graphs with 100 points

I'm trying to make the list of all 2-connected subcubic graphs with at most N vertices. I tried this code: ...
3
votes
1answer
65 views

Permutations and Combinations of Binary Values

I am working on optimization of multipole magnets. Reduction of the number of possible configurations of the magnets essentially becomes the unique determination of the minimum value for all possible ...
1
vote
3answers
46 views

Generate a list of the product of combinated terms in groups of 2

Here is what I have: j1=2 Do[Print[w[m1, n1] = ToExpression["w" <> ToString[m1] <> ToString[n1]]], {m1, 1, j1}, {n1, 1, j1}] That's what I got:...
1
vote
3answers
287 views

How to use Mathematica to solve this problem of planting tree

To plant trees at the center of each small square in a 3 * 4 rectangular area, it is required that there should be no continuous number of three (or more) trees in three directions of Horizontal, ...
0
votes
1answer
76 views

How to speed up the calculation of the number of $4 \times 4$ Young tableaux

I find the problem of calculating $n \times n$ Young tableaux from here. I can get the number of $3\times 3$ Young tableaux by violent enumeration is $42$: ...
1
vote
1answer
89 views

Manage to save large arrays

Some time ago I asked the following question: Merge list repeating elements I was easily answered and I was satisfied by the answer. However in computing such combinatorics, I saturated the RAM very ...
8
votes
1answer
141 views

Merge list repeating elements

Suppose I have a list with mixed elements {{{a,b},{c,d}},{{e,f},{h,i}}} Is there a way so that I can reshuffle the elements to get the following? ...
7
votes
2answers
762 views

All possible combinations of ways to write an equation

I want to define a function in Mathematica where I get all combinations of an expression, e.g., input: {q,p1,p2} Output: ...
0
votes
0answers
33 views

Evaluation control in constructing table iterators

I'm trying to set up a table to scan over combinatorially many sets of numbers. I want to have all choices of $ ({}^n C_k)\cdot({}^n C_{k}-1)\cdot\ \cdots\ \cdot ({}^n C_{k}-m) $, where I keep ...

1
2 3 4 5
9