From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

permutations of a 6! numerically

Solved!
Go to solution

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?

 

0 Kudos
Message 41 of 57
(1,384 Views)

 


@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. 😄

 

Message 42 of 57
(1,380 Views)

extra kudos for you my man!

0 Kudos
Message 43 of 57
(1,373 Views)

Very nice solution Christian.

 

🙂  Many kudos.

 

0 Kudos
Message 44 of 57
(1,350 Views)

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.

 

18403i9E6A43238BFF8228

Download All
Message 45 of 57
(1,334 Views)

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
(1,329 Views)

What's the difference between the two attachments?

 

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

0 Kudos
Message 47 of 57
(1,327 Views)

Post collision earlier.

0 Kudos
Message 48 of 57
(1,321 Views)

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

0 Kudos
Message 49 of 57
(1,305 Views)

 


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.

Message 50 of 57
(1,301 Views)