TreeRex
TreeRex

Reputation: 517

Algorithm for finding string permutations where each position varies

Let's say I have a three character string "ABC". I want to generate all permutations of that string where a single letter can be replaced with his lower-case equivalent. For example, "aBC", "abC", "abc", "AbC", "Abc", etc. In other words, given a regexp like [Aa][Bb][Cc] generate every string that can be matched by it.

Upvotes: 0

Views: 78

Answers (1)

NPE
NPE

Reputation: 500227

The problem can be trivially reduced to generating all binary sequences of length n. This has been previously addressed, for example in Fastest way to generate all binary strings of size n into a boolean array? and all permutations of a binary sequence x bits long.

Upvotes: 2

Related Questions