<p>This is the same as picking a subset and replacing the elements in the subset with X</p>

CC BY-SA 3.0
2013-10-01T13:34:19.707Z
2013-10-01T13:34:19.707Z
dpington
<p>I need to calculate the combinations of elements with a substitution element.</p>

<p>For example for elements <code>[A,B]</code> if the substitution is X the results should be <code>{[A,X],[X,B],[X,X]}</code>. While this is easy enough to implement when the number of elements increase it becomes harder and error prone.</p>

<p>Is there an algorithm I can implement for this kind of combination calculations?</p>

<p>If this question is not a good fit for this site I do apologize, but this is the best site for an algorithmic question as far as I can tell.</p>

<p>EDIT :</p>

<p>I should have mentioned that all results should be of the same length as well.</p>

CC BY-SA 3.0
2013-10-01T09:55:45.230Z
This is the same as picking a subset and replacing the elements in the subset with X.
dpington
CC BY-SA 3.0
2013-10-01T10:27:23.147Z
Make that an answer, I can work from there, thank you.
Thihara
CC BY-SA 3.0
2013-10-01T18:02:49.493Z
This seems more suitable for [cs.se] which has a broader scope, for the scope of [cstheory.se] please check [about] and [help/on-topic].
Kaveh
<ds.algorithms><permutations><combinatory-logic>
Algorithm for calculating substitution combination with ordering
Thihara
# Algorithm for calculating substitution combination with ordering

(Asked by: username_0 on 2013-10-01)

I need to calculate the combinations of elements with a substitution element.

For example for elements `[A,B]` if the substitution is X the results should be `{[A,X],[X,B],[X,X]}`. While this is easy enough to implement when the number of elements increase it becomes harder and error prone.

Is there an algorithm I can implement for this kind of combination calculations?

If this question is not a good fit for this site I do apologize, but this is the best site for an algorithmic question as far as I can tell.

EDIT :

I should have mentioned that all results should be of the same length as well.

**Tags:** ds.algorithms, permutations, combinatory-logic

> **Comments:**
> **username_1**: This is the same as picking a subset and replacing the elements in the subset with X.  
> **username_0**: Make that an answer, I can work from there, thank you.  
> **username_2**: This seems more suitable for [cs.se] which has a broader scope, for the scope of [cstheory.se] please check [about] and [help/on-topic].  

---

## 1 answers

### Answer by username_1 on 2013-10-01. Score: 1 | Accepted answer

This is the same as picking a subset and replacing the elements in the subset with X


---

