Permutations

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.
 
K

kimiraikkonen

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
 
S

SurturZ

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! :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top