Combinatorics - 01 - MATLAB Cody - MATLAB Central

Problem 45303. Combinatorics - 01

Difficulty:Rate
  • Input=[x,n]
  • where x is an array of numbers(or strings) and n is a +ve number.

for example, x=[1,2] and n=6.

The output will be a matrix containing all the possible permutations of the vector x having n elements(no of columns=n). besides that -

  • each row should contain equal number of occurance of the elements of x. (3 ones, 3 twos)
  • no initial segment can have more 2's than 1's. e.g. [2 2 1 2 1 1] - is invalid.since there are more 2's in the 1st appearance than 1's.
  • y=[
     1     1     1     2     2     2
     1     1     2     1     2     2
     1     1     2     2     1     2
     1     2     1     1     2     2
     1     2     1     2     1     2
     1     2     1     2     2     1
     2     1     1     1     2     2
     2     1     1     2     1     2
     2     1     1     2     2     1
     2     1     2     1     1     2
     2     1     2     1     2     1
     2     1     2     2     1     1
     2     2     1     1     1     2
     2     2     1     1     2     1
     2     2     2     1     1     1]

Solution Stats

13.46% Correct | 86.54% Incorrect
Last Solution submitted on May 01, 2025

Problem Comments

Solution Comments

Show comments
PIVlab surpasses 100K all-time File Exchange downloads
During the past twelve months, PIVlab, a MATLAB Community Toolbox for particle...
4
8
LLMs with MATLAB updated to support the latest OpenAI Models
Large Languge model with MATLAB, a free add-on that lets you access...
2
4

Problem Recent Solvers5

Suggested Problems

More from this Author165

Problem Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!