Info

This question is closed. Reopen it to edit or answer.

5 places are there, 3 dolls is there to arrange with name F,N,M. repitation allowed. how to code in matlab ?

1 view (last 30 days)
related to permutation and combination

Answers (1)

Geoff Hayes
Geoff Hayes on 15 Nov 2015
Jishnu - this seems like a homework question, so rather than just give you the answer, here are some hints. If you had two characters,'F' and 'N', and there is only one place, then the answer is clear
'F'
'N'
If you had two characters and two places, then the answer is
'FF'
'FN'
'NF'
'NN'
Try and see the pattern - we start with one character 'F' and then iterate over the set of characters to fill one place (which is what we did originally) and so we prepend the 'F' to that set to get
'FF'
'FN'
We then repeat for 'N' to get
'NF'
'NN'
So our original problem was to start with two characters to fill two places, which we then replaced with iterating over each character to prepend with the set of characters with only one place to fill. If you had three places to fill, you would do the same thing - reduce the problem to two spaces and then one space.
Try solving this problem using a recursive function. If you get stuck, copy and paste what you have tried and we will help you from there.

Community Treasure Hunt

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

Start Hunting!