Search Results
Search type | Search syntax |
---|---|
Tags | [tag] |
Exact | "words here" |
Author |
user:1234 user:me (yours) |
Score |
score:3 (3+) score:0 (none) |
Answers |
answers:3 (3+) answers:0 (none) isaccepted:yes hasaccepted:no inquestion:1234 |
Views | views:250 |
Code | code:"if (foo != bar)" |
Sections |
title:apples body:"apples oranges" |
URL | url:"*.example.com" |
Saves | in:saves |
Status |
closed:yes duplicate:no migrated:no wiki:no |
Types |
is:question is:answer |
Exclude |
-[tag] -apples |
For more details on advanced search visit our help page |
Questions on the use of Mathematica in combinatorics, including the Combinatorica add-on package.
3
votes
Advanced Tupling
Here is a very procedural approach. Could be shortened somewhat; not sure it would give a speed gain or otherwise be worth the trouble.
ll = {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 17,
…
3
votes
Sum of list numbers smaller than one goal
Could use integer linear programming via Maximize, for example. The constraint I use is overkill, all we really need to enforce is that values be nonnegative.
vals = {140, 280, 420, 560, 700};
goal = …
3
votes
Using FindInstance for Identifying Feasible Planar Solutions in a 3D Latin Hypercube
One way to get a single solution faster is to set it up as a feasibility problem and use FindMinimum. This in turn uses fast machine precision linear programming under the hood.
I recast as a 0-1 ILP …
6
votes
Solving variant of the knapsack/money-changing problem
Not really what you want, but you can find the closest hit using FindMinimum, as below.
n = 6;
target = 10;
SeedRandom[1111];
vals = RandomReal[1, n];
coeffs = Array[c, 6];
c1 = Map[# >= 0 &, coeff …
10
votes
Accepted
How to enumerate multisets?
This will generate all of them, just like Tuples. Not too hard to redo so as to get one at a time. Just use the correspondence between k-digit numbers base n (n=length of input set) and subsets length …
9
votes
Integer partitions without repetitions
Could set this up as a 1-0 integer linear programming problem.
Module[{vars = Array[a, 10]},
vars*Range[10] /.
Solve[Flatten@{vars.Range[10] == 28, Total[vars] == 4,
Map[0 <= # <= 1 &, v …
4
votes
Find k smallest sum n-tuples
Could do this as a polynomial algebra problem with matrix values used as exponents, with a distinct variable for each, summed in rows and product taken of row sums. Use a distinct variable to record t …
1
vote
How to set a custom number field to solve this equation
This might not be any better than a brute force check of all tuples, but it can be recast as an integer linear programming problem, mostly with 0-1 variables. The idea is to use a sum of the form -1*a …
7
votes
Combinatorica: Girth[] and FindCycle[] disagreement
Edited for correctness:
I use the variant for directed graphs from here. I take your graph as above, extract edges, rename so vertices are integers from 1 to #vertices. After finishing we revert to t …
6
votes
Accepted
How to generate 3-subsets that satisfy certain conditions without post-filtering?
One way is to place the first element in each of the subsets formed from s-1 of the remaining elements, find complements, and recursively subdivvy those complements.
subsetSubsets[set_, s_ /; s <= 0] …
7
votes
(Efficiently) Generating graphs with vertex degree 3 for all vertices
This might get you started. It generates (I think) all graphs of given number of vertices and degree, with the following caveats:
They are undirected.
They do not have self edges.
Edges only have we …
13
votes
Accepted
Combination and Permutation
Take all subsets of length 10, then for each one find all splits into two sets of five such that the first of the ten is in the first part of the split.
In[29]:= Timing[
msets = Subsets[Range[12], { …
6
votes
How do I generate the upper triangular indices from a list?
Could do this procedurally by constructing iterator lists.
indices[n_, max_] := Module[
{jj = Array[j, n], starts, ends},
starts = Prepend[Most[jj] + 1, 1];
ends = max - Range[n - 1, 0, -1];
…
7
votes
How to improve the performance of solutions to Project Euler (#39)?
Not fastest, but gives an idea of how Solve might be used with tolerable efficiency.
In[181]:= Timing[
soln = Solve[{x^2 + y^2 - z^2 == 0, z >= y - 1 >= x - 1 >= 0,
0 <= x + y + z <= 1000}, {x …
9
votes
find the number of integral solutions a+b+c+d+e+f = 18
Depending on whether you care about permutations or not, here are some ways to go about it.
One is to solve a system of equations via Reduce and count the solutions.
vars = Array[a, 6];
eqn = Total[ …