Problem 45303. Combinatorics - 01

  • 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

14.89% Correct | 85.11% Incorrect
Last Solution submitted on Mar 08, 2024

Problem Comments

Solution Comments

Show comments

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!