Permutations

  • Thread starter Thread starter SurturZ
  • Start date Start date
S

SurturZ

This is a bit of a basic question.

I have an array of names that the user has entered (up to 4). I want to
check every permutation of those names against the four different name fields
in the database (First, Last, Middle and Alias). No repetition in names, each
search term is used once per query.

How do I generate every permutation of the names? e.g. ABCD, ABDC, ACBD,
ACDB... etc?

Is there a formula, or do I just hardcode?

Ideally, I'd like a formula that returns every permutation for an array of
size N, but a specific solution for N=4 is okay too.
 
This is a bit of a basic question.

I have an array of names that the user has entered (up to 4). I want to
check every permutation of those names against the four different name fields
in the database (First, Last, Middle and Alias). No repetition in names, each
search term is used once per query.

How do I generate every permutation of the names? e.g. ABCD, ABDC, ACBD,
ACDB... etc?

Is there a formula, or do I just hardcode?

Ideally, I'd like a formula that returns every permutation for an array of
size N, but a specific solution for N=4 is okay too.

Hi,
That link may help you:
http://www.mredkj.com/vbnet/permutation.html

Thanks,

Onur Güzel
 
Thanks!

I actually went ahead and wrote a recursive function to do it, but yours
might be a better solution.

I'm glad that it's non-trivial.

I was also surprised that there is no factorial function in the Math
namespace... so employers can continue to use it as an interview question I
suppose! :-)
 
Back
Top