1
$\begingroup$

The list I have is

{a,b,c,d,e}

I would like to use ReplaceList to construct a list of three-element subset of the above list.

This would require the use of BlankSequence but I do not understand how it works.

Any help is appreciated.

Thanks in advance.

$\endgroup$
  • $\begingroup$ Have you seen Subsets[]? $\endgroup$ – J. M. is in limbo Mar 27 '17 at 14:47
  • $\begingroup$ @Szabolcs I never thought it was a good idea but this came up in an as an exercise in mathematical physics. Would you explain to me how BlackSequence works? $\endgroup$ – Physkid Mar 27 '17 at 14:50
  • $\begingroup$ @Szabolcs It says "three element subset of the list {a,b,c,d,e}" $\endgroup$ – Physkid Mar 27 '17 at 14:51
  • $\begingroup$ @Szabolcs It's sort of a prelude...I'm not new to Mathematica but there are stuffs like pattern matching and conditions which aren't something that a non-computer science student would be intimately acquainted with on a daily basis; hence, the bit of obstacles. $\endgroup$ – Physkid Mar 27 '17 at 14:51
  • $\begingroup$ @J.M. I have. But how does this aid with determining all possible three-elements of a set/list? $\endgroup$ – Physkid Mar 27 '17 at 14:54
3
$\begingroup$

You can use

ReplaceList[{a, b, c, d, e}, {___, x_, ___, y_, ___, z_, ___} -> {x, y, z}]
(* {{a, b, c}, {a, b, d}, {a, b, e}, {a, c, d}, {a, c, e}, 
    {a, d, e}, {b, c, d}, {b, c, e}, {b, d, e}, {c, d, e}} *)
$\endgroup$
  • $\begingroup$ How does BlankSequence works? I've looked at the documentation but it isn't clearly explained. $\endgroup$ – Physkid Mar 27 '17 at 14:54
  • $\begingroup$ @Physkid This is BlankNullSequence. I find the explanation in the documentation quite clear: "a pattern object that can stand for any sequence of zero or more Wolfram Language expressions". I am honestly not sure what more can be said, so the ball is in your court to explain why you are having trouble with it. $\endgroup$ – Szabolcs Mar 27 '17 at 14:57
  • $\begingroup$ If you like it better that way: ___ will match any number of comma separated things. $\endgroup$ – Szabolcs Mar 27 '17 at 14:57
  • $\begingroup$ What does it mean by 'Pattern object'? $\endgroup$ – Physkid Mar 27 '17 at 14:58
  • 4
    $\begingroup$ You must read this: wolfram.com/language/fast-introduction-for-programmers/en/… and this: reference.wolfram.com/language/tutorial/PatternsOverview.html in full before asking any more pattern related questions. $\endgroup$ – Szabolcs Mar 27 '17 at 14:59

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