3
$\begingroup$

I've created a permutation list

Grid[Permutations[{a, e, q, r, t, u}], Frame -> All]

and only want to see rows where the 5th element is a "t". I tried to do use FilterRules, but I don't understand how to use them as shown below.

Grid[FilterRules[Permutations[{a, e, q, r, t, u}], Frame -> All], {, , , , t,}]

Could somebody please help me.

$\endgroup$
2
  • 3
    $\begingroup$ Cases[Permutations[{a, e, q, r, t, u}], {Repeated[_, {4}], t, _}], which you can then wrap in Grid for presentation as well: Grid[Cases[ ... ], Frame -> All]. $\endgroup$
    – MarcoB
    Oct 1, 2015 at 2:23
  • 1
    $\begingroup$ FilterRules is for handling options. $\endgroup$
    – m_goldberg
    Oct 1, 2015 at 3:09

2 Answers 2

6
$\begingroup$

Just some other approaches:

perm = Permutations[{a, e, q, r, t, u}];
pm = Permutations[{a, e, q, r, u}];

The following:

pck = Pick[perm, #[[5]] & /@ perm, t];
sel = Select[perm, #[[5]] == t &];
con = #[[1 ;; 4]]~Join~{t}~Join~{#[[5]]} & /@ pm;
$\endgroup$
3
  • $\begingroup$ I'd do equivalently con = Most@#~Join~{t, Last@#} & /@ pm $\endgroup$
    – LLlAMnYP
    Oct 1, 2015 at 9:14
  • $\begingroup$ @LLlAMnYP yes...thank you $\endgroup$
    – ubpdqn
    Oct 1, 2015 at 9:16
  • 1
    $\begingroup$ @LLlAMnYP I did not interpret it as rude but as a useful comment. Comments and edits are part of the nice learning environment of the site. Sometimes I miss the obvious, am unusually ham-fisted, over complicate and sometimes I am just trying to be illustrative of the wonderful variety...so thank you not sarcasm...if you want to edit feel free...just thought comment thread enough :) $\endgroup$
    – ubpdqn
    Oct 1, 2015 at 9:22
5
$\begingroup$

Thanks to MarcoB, there is the final code:

Grid[
  Cases[Permutations[{a, e, q, r, t, u}], {Repeated[_, {4}], t, _}], 
  Frame -> All]
$\endgroup$

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