Hello there.
I would like to know what are the possible combinations of 3 elements at a time, in a group of 5.
What is the right commands to give to mathematica?
Thanks in advance for any help.
Nevermind, I found a way to do this.
Here it is:
bevande = {" caffe", " latte", " orzo", " cioccolata", " the"}
For[i = 1, i <= 5, i++, For[j = i + 1, j <= 5, j++, For[k = j + 1, k <= 5, k++, Print[bevande[[i]], bevande[[j]], bevande[[k]]]] ]]
Thanks anyhow.
In[8]:= bevande = {" caffe", " latte", " orzo", " cioccolata", " the"};
In[9]:= Subsets[bevande, {3}]
Out[9]= {{" caffe", " latte", " orzo"}, {" caffe", " latte",
" cioccolata"}, {" caffe", " latte", " the"}, {" caffe", " orzo",
" cioccolata"}, {" caffe", " orzo", " the"}, {" caffe",
" cioccolata", " the"}, {" latte", " orzo",
" cioccolata"}, {" latte", " orzo", " the"}, {" latte",
" cioccolata", " the"}, {" orzo", " cioccolata", " the"}}
In[10]:= Permutations[bevande, {3}]
Out[10]= {{" caffe", " latte", " orzo"}, {" caffe", " latte",
" cioccolata"}, {" caffe", " latte", " the"}, {" caffe", " orzo",
" latte"}, {" caffe", " orzo", " cioccolata"}, {" caffe", " orzo",
" the"}, {" caffe", " cioccolata", " latte"}, {" caffe",
" cioccolata", " orzo"}, {" caffe", " cioccolata",
" the"}, {" caffe", " the", " latte"}, {" caffe", " the",
" orzo"}, {" caffe", " the", " cioccolata"}, {" latte", " caffe",
" orzo"}, {" latte", " caffe", " cioccolata"}, {" latte", " caffe",
" the"}, {" latte", " orzo", " caffe"}, {" latte", " orzo",
" cioccolata"}, {" latte", " orzo", " the"}, {" latte",
" cioccolata", " caffe"}, {" latte", " cioccolata",
" orzo"}, {" latte", " cioccolata", " the"}, {" latte", " the",
" caffe"}, {" latte", " the", " orzo"}, {" latte", " the",
" cioccolata"}, {" orzo", " caffe", " latte"}, {" orzo", " caffe",
" cioccolata"}, {" orzo", " caffe", " the"}, {" orzo", " latte",
" caffe"}, {" orzo", " latte", " cioccolata"}, {" orzo", " latte",
" the"}, {" orzo", " cioccolata", " caffe"}, {" orzo",
" cioccolata", " latte"}, {" orzo", " cioccolata",
" the"}, {" orzo", " the", " caffe"}, {" orzo", " the",
" latte"}, {" orzo", " the", " cioccolata"}, {" cioccolata",
" caffe", " latte"}, {" cioccolata", " caffe",
" orzo"}, {" cioccolata", " caffe", " the"}, {" cioccolata",
" latte", " caffe"}, {" cioccolata", " latte",
" orzo"}, {" cioccolata", " latte", " the"}, {" cioccolata",
" orzo", " caffe"}, {" cioccolata", " orzo",
" latte"}, {" cioccolata", " orzo", " the"}, {" cioccolata", " the",
" caffe"}, {" cioccolata", " the", " latte"}, {" cioccolata",
" the", " orzo"}, {" the", " caffe", " latte"}, {" the", " caffe",
" orzo"}, {" the", " caffe", " cioccolata"}, {" the", " latte",
" caffe"}, {" the", " latte", " orzo"}, {" the", " latte",
" cioccolata"}, {" the", " orzo", " caffe"}, {" the", " orzo",
" latte"}, {" the", " orzo", " cioccolata"}, {" the", " cioccolata",
" caffe"}, {" the", " cioccolata", " latte"}, {" the",
" cioccolata", " orzo"}}
Wow, was it that easy? Thanks. I have a lot to learn.
Have a nice day.
You are welcome. Ivano. Mathematica is such a high-level language that procedural constructs are seldom needed, I also added the permutations, in case order matters.
Thanks again. no, order doesn’t matter.