Message Boards Message Boards

0
|
3288 Views
|
1 Reply
|
1 Total Likes
View groups...
Share
Share this post:

How to select all permutations that follow certain rules

Posted 4 years ago

I'm new to Wolfram Language and still learning.

Suppose I have a set: {a,b,c,...}
I want to get a list of all possible permutations of length N that follow certain rules.
For example:

  • b must neighbor c
  • a must come before c
  • between b and d must be c
  • between a and e must be 6 elements
  • and so on...

Maybe even lists where elements could appear multiple times, not just permutations.

Where can I learn how to use pattern matching?
Is something like this possible/easy?
Could you give examples how I can get those lists?

POSTED BY: Nico G

There is a tutorial about pattern matching :

http://reference.wolfram.com/language/tutorial/Patterns.html

As for your question, I think you may need to specify an order relation operator, so you want to generate all permutations of Range[n]. It will be easier than using the symbols a, b, c, ...

For simple cases you don't have to, though. For instance if you want all permutations that keep "b" and "c" close together and in that order, you can write :

Cases[Permutations[{a,b,c,d,e}], {___, b, c, ___}]
POSTED BY: Lucien Grondin
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract