Group Abstract Group Abstract

Message Boards Message Boards

0
|
9.5K Views
|
3 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Permutations with conditions: element a to appear before c

Posted 11 years ago
POSTED BY: Lara Craft
3 Replies
Posted 9 years ago

I believe this works too

Clear[a, b, c, d, e]; Sort /@ 
 Select[Tuples[{a, b, c, d, e}, {3}], Count[#, b] <= 1 &]
POSTED BY: Paul Cleary
Posted 9 years ago

A couple of ways come to mind. Both delete the cases that are not wanted from the output of the permutation generator.

aa = {a, b, c, d, e};
p1 = DeleteCases[
  Tuples[{aa, aa, aa}], {___, c, ___, a, ___} | {___, b, ___, b, ___}];
bb = {a, a, a, b, c, c, c, d, d, d, e, e, e};
p2 = DeleteCases[Permutations[bb, {3}], {___, c, ___, a, ___}];

p1 and p2 are the same list.

POSTED BY: Larry Morris

There might be a clever way to do this, but let's focus on defining functions that test your two properties

testA[list_] := Count[list, b]<2

testB[list_] := If[MemberQ[list, a] && MemberQ[list, b], 
                   First@FirstPosition[list, a] < First@FirstPosition[list, b], 
                   True]

You can use these functions with Select

POSTED BY: Sean Clarke
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard