# LabVIEW

cancel
Showing results for
Did you mean:

Solved!
Go to solution

## Re: permutations of a 6! numerically

Is it possible to change it from an array of say A B C D E F  to a word as in:- ABCDEF as a single element?

Message 41 of 57
(691 Views)

## Re: permutations of a 6! numerically

@John Pierson wrote:

Is it possible to change it from an array of say A B C D E F  to a word as in:- ABCDEF as a single element?

Yes, my second example does that. 😄

LabVIEW Champion. It all comes together in GCentral
What does "Engineering Redefined" mean??
Message 42 of 57
(687 Views)

## Re: permutations of a 6! numerically

extra kudos for you my man!

Message 43 of 57
(680 Views)

## Re: permutations of a 6! numerically

Very nice solution Christian.

🙂  Many kudos.

______________________________________________________________________
Message 44 of 57
(657 Views)

## Re: permutations of a 6! numerically

Could have been fun, too bad late lunch on West Coast means slow on the draw.  At any rate, the OP has a solution so I do not have to worry about minor details like saving for 8.2. The classic recursion solution is elegant (like most recursive solutions), but native recursion (in LV9+) is slow, and VI server recursion is downright glacial.  I think the physicist side of DFGray showed up, rolling the dice is a simple-yet-effective treatment in these cases, I would probably have been putting Riffle to good use here.

Altenbach's solution is (needless-to-say) masterfully efficient, I only have a few quibbles.  It assumes the elements are distinct, but oftentimes, especially with letters, elements can be repeated.  Second, while there is considerable in-placeness, it is often not the best idea to be carrying around all possible combinations since that can become quite a large number in a hurry.

So, given this good excuse to dust off Knuth's book, and as an added bonus implement a 700 year old algorithm, here is my take.  Shamelessly LV9.0 (or at least 8.6 for the IPE and conditional For Loops).  This routine is seriously in-place, each time it is run it generates the next permutation given the previous one.  Using for example the letters 'aab' it returns only three permutations instead of six.

Message 45 of 57
(641 Views)

## Re: permutations of a 6! numerically

Oops.  seemed to attach same file twice last time.  Here is the VI which uses a while loop to find all permutations.  Better hurry before altenbach notices...

Message 46 of 57
(636 Views)

## Re: permutations of a 6! numerically

What's the difference between the two attachments?

EDIT: Nevermind, just saw your new post... 😉

LabVIEW Champion. It all comes together in GCentral
What does "Engineering Redefined" mean??
Message 47 of 57
(634 Views)

## Re: permutations of a 6! numerically

Post collision earlier.

Message 48 of 57
(628 Views)

## Re: permutations of a 6! numerically

Looks good. Do you have a link to the algorithm?

(One minor flaw: an empty string input should probably give an empty array as output.)

LabVIEW Champion. It all comes together in GCentral
What does "Engineering Redefined" mean??
Message 49 of 57
(612 Views)

## Re: permutations of a 6! numerically

altenbach wrote:

(One minor flaw: an empty string input should probably give an empty array as output.)

Quick fix:

In the TRUE case, check for "empty string?" and wire the output to the tunnel, replacing the boolean diagram constant.

LabVIEW Champion. It all comes together in GCentral
What does "Engineering Redefined" mean??
Message 50 of 57
(608 Views)