Let's say I want to find a sample space of such experiment: There are three exits from the box: Left (L), right (R) and front (F). Three mice have been put in that box. Find the sample space of an event which mouse has chosen which exit. Function Permutations[] gives all different outputs.


How can I find also outcomes like {F,F,L}, {R,R,R}... ?

  • 3
    $\begingroup$ It's only terminology. The OP has to state if he/she wants variations or combinations. (In other words: Is (LLF) the same as (LFL)?) $\endgroup$
    – Stefan
    Feb 18, 2013 at 14:48
  • 3
    $\begingroup$ @Ajasja When I use your example, I don't get the event {RRR} which the OP demanded. So Permutations does NOT give the asked results. $\endgroup$
    – Stefan
    Feb 18, 2013 at 15:02
  • 3
    $\begingroup$ @Misery Please try to re-state your question in an easier to understand way, to avoid all these close and reopen votes. I'd suggest giving an example input and the complete output your desire. $\endgroup$
    – Szabolcs
    Feb 18, 2013 at 15:10
  • 2
    $\begingroup$ Question should be restated as: Given a list of 3 distinct objects, how does one form the list of all possible triples of these objects, repetitions allowed? $\endgroup$
    – murray
    Feb 18, 2013 at 15:17
  • 2
    $\begingroup$ I disagree that his question is too localize: 4 upvotes and 6 upvotes on accepted answer shows that it is helping new visitors. I suggest removing the closure by lack of evidence supporting localization. $\endgroup$ Oct 16, 2013 at 9:32

2 Answers 2

 Tuples[{l, r, f}, 3]
 (* {{l, l, l}, {l, l, r}, {l, l, f}, {l, r, l}, {l, r, r}, {l, r, f}, 
    {l, f, l}, {l, f, r}, {l, f, f}, {r, l, l}, {r, l, r}, {r, l, f}, 
    {r,  r, l}, {r, r, r}, {r, r, f}, {r, f, l}, {r, f, r}, {r, f, f},
    {f, l,  l}, {f, l, r}, {f, l, f}, {f, r, l}, {f, r, r}, {f, r, f}, 
    {f, f,  l}, {f, f, r}, {f, f, f}} *)



The only problem is that you have a recursive definition ( you want L to be a list and outcome).

In general using identifiers that start with a capital letter is best avoided. D and C are some examples of this.

This is much safer and works as expected:

list = {"L", "R", "F"}

If you would like to have "permutations with repetition" then Tuples is the right tool for the job (as kguler already noted):

Tuples[list, 3]
  • $\begingroup$ And E, and I, and N, and O... $\endgroup$ Feb 18, 2013 at 14:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.