All Questions

Filter by
Sorted by
Tagged with
0
votes
1answer
33 views

Expanding integer compositions

Quick version: I would like Mathematica code that, for instance, turns {3,1,2} into {3,3,3,1,2,2}. More formally, given positive integers $c_1, \ldots, c_t$ which sum to $n$, produce the length $n$ ...
5
votes
1answer
526 views

Is there a function to partition an integer set?

First I give an example. For an integer set $(0,1,2,3,4)$, there are eight kinds of subdivision or partition like this $$(0,4);\\~~(0,1)(1,4);~~(0,2)(2,4);~~(0,3)(3,4);\\ (0,1)(1,2)(2,4);~~(0,1)(1,3)(...
5
votes
3answers
422 views

Find position without iterating

The code below solves for the four value of $m_i$ for a given pair of $(N_m,M_m)$. where $$ m_1+m_2+m_3+m_4 = M_m\\ |m_1|+|m_2|+|m_3|+|m_4| = N_m $$ Edit 2 New Sorting I have now realised that the ...
0
votes
2answers
75 views

Tuples of elements from list excluding anything with repeated values

What I would like to do is the following. For a given list of elements; say (0,1,2,3,4) I would like to obtain all possible combinations of five, but not the ones with ANY repeated values. That is I ...
4
votes
2answers
59 views

Groupings of the Elements of a List with at Most $k$ Elements

Given a list with $n$ elements and an integer $k$ I want to get a list with all possible groupings of these n elements in sets with at most k elements. For example, given $n=\{1,2,3,4\}$ and $k=3$ I ...
3
votes
1answer
267 views

How to calculate all possible resistances made from 5 distinct resistors in series and/or parallel? [closed]

Five distinct resistors resistors={1,2,3,4,5} are given. The objective is to find a list of all possible resistances obtained by configuring all these resistors in ...
12
votes
4answers
408 views

How to generate all involutive permutations?

Take a finite set $S$ (i.e., a list). An involutive permutation is one that squares to the identity. How can we generate all such permutations efficiently, that is, without generating all permutations ...
1
vote
0answers
45 views

Generating list of binomial outcomes [closed]

As an example, imagine if I have a set of 3 coins and I want to generate a list of possible coin states. I know I can brutishly execute: ...
4
votes
2answers
238 views

Scramble matrix under some condition

Assume I have a matrix. (mat = Partition[Range@9, 3]) // MatrixForm mat$=\left( \begin{array}{ccc} 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & ...
0
votes
1answer
49 views

Separate list elements into groups of two in all possible ways? [duplicate]

Consider a list with an even number of elements, e.g. list = {1,2,3,4}; I would like to have a function fun that produces all ...
5
votes
3answers
867 views

Combine two lists with all possible combinations

I have the following lists: list1={1,2,3,4,5}; list2={10,20,30,40,50}; I want to combine these lists such that each element in ...
3
votes
2answers
191 views

Generating invertible matrix with lines within a given set

Consider the set options given as below ...
2
votes
2answers
505 views

Cartesian product of more than two sets

Here you see how to produce a cartesian product of two sets. How can we obtain the cartesian product of three or more sets? CartesianProduct[l1,l2,l3] doesn't work....
3
votes
2answers
91 views

Obtaining all possible ways to concatenate matrices

With Prepend we can add a line to all matrices in a set, like this: ...
3
votes
0answers
59 views

Lazy tuples made from arbitrary lists [duplicate]

I am dealing with Tuples of n lists each having potentially different length: longList = Tuples[list1, list2, ..., listn]: Since I have to iterate over the ...
0
votes
1answer
174 views

List all possible microstates and corresponding energy using mathematica.

Consider 10 identical indistinguishable particles placed on 3 energy states with energy mgh, 2mgh,3mgh respectively.List all possible microstates and corresponding energies. I am a physics student ...
3
votes
4answers
186 views

Listing all distinct exhaustive combinations of sublists of a certain length [duplicate]

I would like to do the following: Suppose there is a list {a, b, c, d}. I would like to get all distinct exhaustive combinations of its sublists of a certain ...
3
votes
1answer
88 views

Select out of nested list

I have a nested list: {{{1, 2, 3, 4, 5, 6}}, {{1}, {2, 3, 4, 5, 6}}, {{1, 2}, {3}, {4, 5, 6}}} and would like to select only those lists out of it with two items ...
0
votes
0answers
369 views

Splitting a list into 2 sublists in all possible ways

I have a list and I want to split it into 2 sublists in all possible ways If S={1,2,3,4} I should get ...
7
votes
1answer
144 views

Fast creation of state transitions and probabilities?

Normally I'd wait until I'd fleshed/thought things out further but I find this interesting enough that I think others might. Take an ordered list of $N$ slots, integers from $[0,2]$. This represents ...
10
votes
3answers
544 views

Permutations of lists of fixed even numbers

Let's say we have this list list={3,6,5,21,23,76,1,28,96,54,77} I would like to know the number of permutations when every even number stays where it is and ...
7
votes
3answers
1k views

List all possible license plate numbers

The length of license plate numbers is 6, with 2 letters and 4 numbers. The first two characters are letters and the last four are numbers. Example: AA1234. This is the code I have so far: ...
8
votes
1answer
192 views

Doing combinations of sub-sublists

To create a list of all the possible combinations of a sublist. I have a list, somewhat resembling the following format: ...
0
votes
1answer
105 views

How do you group cycles?

I want to define a function that takes a list of pairs as input and groups cycles, e.g. {{a1,a2},{b1,b2},{a2,a3},{c1,c2},{a3,a1},{b2,b1}} becomes ...
4
votes
4answers
255 views

Listing sequence with rules

How would one go about listing all sequences S length 10 made up of a combination of a's and ...
3
votes
2answers
85 views

Producing a list of all the pairs can be made by from two lists of equal length [closed]

I have two lists: {x1, x2, x3, x4, x5} and {y1, y2, y3, y4, y5} How can I get a list like the one below from them, where ...
4
votes
2answers
225 views

How to derive large Tuples (25^25, 50^50,100^100) under certain condition

My problem is that computer has no sufficient memory to calculate tuples of my list. A simple example can be given as follows: ...
4
votes
1answer
253 views

How to efficiently generate unique combination from several lists

For example I have a list data={{1,3,2},{3,2,4},{2,4,3}} sublist of data has no duplicate elements. We know ...
21
votes
3answers
1k views

Solving word search puzzles

I am trying to create a code that can identify the following terms in a grid of letters: MATHEMATICA, STACK, EXCHANGE and USERS. ...
20
votes
6answers
642 views

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

This question is hard to describe in plain text. So I will post an example and a working code (brute force) to illustrate. For example I have a list: ...
2
votes
1answer
150 views

How to list all binary expression trees with given leaves

If i have a list of leaf nodes and nonleaf nodes with specified arities, how can I effieciently enumerate the possible trees? For example: ...
13
votes
6answers
628 views

how to permute list of number{1,2,3,…,n},while preserve the order of first m terms as well as the last n-m terms?

For example, starting from {1,2,3,4}, I want to generate all permutations like {1,3,2,4},{1,3,4,2},{3,4,1,2} which preserve the ...
0
votes
1answer
50 views

Combination of Values: Automated generation [closed]

How can I get a list of combinations for two values (e.g. 0 and a) such as for N=3: {{a,a,a},{a,a,0},{a,0,a},{0,a,a},{a,0,0},{0,a,0},{0,0,a},{0,0,0}} ? I'd like ...
2
votes
1answer
98 views

How to split a SymmetricGroup into some PermutationGroup with smaller GroupOrder

Background I want to get a permutation list, so I use the SymmetricGroup(or use Permutations) to produce it when the ...
8
votes
1answer
144 views

Generalizing LongestCommonSequence to 3 or more arguments?

The function LongestCommonSequence finds a longest common subsequence between 2 lists. Apparently, this built-in function does not accept more than 2 arguments. How ...
3
votes
1answer
60 views

Returning maxima of multiple sets

I am trying to prove a conjecture which involves the SetParitions[n] function (which requires the Combinatorica package). This function returns a list of all the set partitions of n. I'd like to take ...
6
votes
3answers
340 views

How to partition a set with a condition on subsets?

I want to partition a set of $n$ elements into $k$ subsets with a condition For example: partitioning this set {1,...,5} into 3 subsets with this condition: if $|i-j|<d$ then $i$ can't be with $j$ ...
11
votes
4answers
464 views

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

This is less a question and more asking if someone has implemented this already, with more skill. I need to perform the Outer-like generalized outer product of a ...
8
votes
4answers
884 views

Tuples with one “joker” digit? [duplicate]

I'd like to create an array of all possible length 11 combinations of 1, 2, and the number 3, BUT with the number 3 only appearing zero or once in each combination. I tried: ...
10
votes
4answers
376 views

Efficient way to make subsets of list with placeholders

I have an arbitrary list of unique elements: lst = {a, b, c, d} Documentation allows finding subsets with same number of elements, say ...
4
votes
1answer
410 views

Efficiently generating tuples with Outer

I'm trying to efficiently generate tuples of lists of objects that satisfy a given criterion. The similar questions that I have found on this website end up finding a specific workaround for the given ...
20
votes
3answers
956 views

Generating Tuples with restrictions

I am interested in a certain subset of all tuples. Generating all with Tuples and then filtering is wasteful, and will "blow up" very quickly. For a concrete ...
4
votes
2answers
217 views

`IntegerPartitions` without duplicates

I need to apply a function to integer partitions of many integers, but only the partitions without duplicate numbers. Select[IntegerPartitions[n], DuplicateFreeQ] ...
1
vote
0answers
80 views

Finding correct combination of functions

I am trying to write code where I have an array $S$ or numbers in any order [5,4,2,1,....] Then I have a specific set of functions that I can write. ...
6
votes
5answers
238 views

Simple Enumeration of Coin Tosses

How do I enumerate a sample space with up to 6 coin tosses where 4 Heads ensures a win. For e.g {HHHH},{HTHHH},{TTHHHH},{HTTHHH} etc.I tried the following but I do not know how to do a variable length ...
4
votes
1answer
517 views

Random Partitions

I want to write a function RandomPartition to partition a vector of length n into p partitions of varying (random) lengths. For example with ...
2
votes
1answer
4k views

How to get all possible combinations of this list? [closed]

I'm trying to get all possible combinations of {0,-1} for a certain length. So let's say I want length 2. Then I want my output to be ...
3
votes
1answer
362 views

Way to generate all multisets

I have a set $\left\{\{1,2\}, \{3,4\}, \{5,6\}, \{7,8\}\right\}$ (for example) and want to generate all sets of $n$ elements with repetition but without counting the same multiset twice. So I want my ...
2
votes
1answer
130 views

Need Help Writing code to find Capparelli Partitions

I am trying to add multiple criterion to IntegerPartitions[n] so that it sorts only partitions that fit the criterion. It creates a list of list of numbers in ...
11
votes
5answers
2k views

Find all the possible ways of partitioning a list into a set of pairs of element

I have a list {x1,...,xN} where N is even, and I need to find all the possible ways to split it into pairs of elements, e.g. the ...