topic Re: How can I create list of permutations in LabVIEW
https://forums.ni.com/t5/LabVIEW/How-can-I-create-list-of-permutations/m-p/1257052#M528126
<P>Sure, give it a shot.</P>
<P>If you get stuck, I should be able to whip up an example later this afternoon.</P>
<P>Good luck!</P>Wed, 22 Sep 2010 20:49:53 GMTCory_K2010-09-22T20:49:53ZHow can I create list of permutations
https://forums.ni.com/t5/LabVIEW/How-can-I-create-list-of-permutations/m-p/1256988#M528108
<P>Hi Everyone,</P>
<P>I need to create a 2 d array which will contain all of the permutations of a 1d input array, specifically, I have a 1 d array of colour boxes and I want to return a 2 d array of colour boxes. This is too mathematical for me! Is there a combination of functions that will help me achieve this? From my days at college I remember something about factorials, but as for coding it...</P>
<P>If anyone has any suggestions I would be very grateful.</P>
<P>Thank you,</P>
<P>Michael.</P>Wed, 22 Sep 2010 20:18:55 GMThttps://forums.ni.com/t5/LabVIEW/How-can-I-create-list-of-permutations/m-p/1256988#M528108Michael_782010-09-22T20:18:55ZRe: How can I create list of permutations
https://forums.ni.com/t5/LabVIEW/How-can-I-create-list-of-permutations/m-p/1257010#M528112
<P>I cannot write you up an example at the moment, because this computer doesn't have LabVIEW, but I can try to explain.</P>
<P> </P>
<P>You will need to recursively call a subVI to generate the permutations.</P>
<P> </P>
<P>Use the array : [a, b ,c]</P>
<P> </P>
<P>- start with an empty array</P>
<P>- for the first element, it the set can either contain it or not:<BR />[], [a]</P>
<P>- for each of those two arrays, it can either contain the next element or not, so you would insert it</P>
<P>[], [a], [b], [ab]</P>
<P>- for those arrays, it can either contain the next element or not, so you would insert:</P>
<P>[], [a], [b], [ab], [c], [ac], [bc], [abc]</P>
<P> </P>
<P>So the subVI would just take the input array, and double it.</P>
<P>For the second half of the new array (the half that was just created), append the most recent element to the end of all the previous elements</P>Wed, 22 Sep 2010 20:37:10 GMThttps://forums.ni.com/t5/LabVIEW/How-can-I-create-list-of-permutations/m-p/1257010#M528112Cory_K2010-09-22T20:37:10ZRe: How can I create list of permutations
https://forums.ni.com/t5/LabVIEW/How-can-I-create-list-of-permutations/m-p/1257050#M528125
<P>Thanks, I'll give it a go.</P>
<P>Michael</P>Wed, 22 Sep 2010 20:47:27 GMThttps://forums.ni.com/t5/LabVIEW/How-can-I-create-list-of-permutations/m-p/1257050#M528125Michael_782010-09-22T20:47:27ZRe: How can I create list of permutations
https://forums.ni.com/t5/LabVIEW/How-can-I-create-list-of-permutations/m-p/1257052#M528126
<P>Sure, give it a shot.</P>
<P>If you get stuck, I should be able to whip up an example later this afternoon.</P>
<P>Good luck!</P>Wed, 22 Sep 2010 20:49:53 GMThttps://forums.ni.com/t5/LabVIEW/How-can-I-create-list-of-permutations/m-p/1257052#M528126Cory_K2010-09-22T20:49:53ZRe: How can I create list of permutations
https://forums.ni.com/t5/LabVIEW/How-can-I-create-list-of-permutations/m-p/1257110#M528135
<P>Assuming that all colors in the input array are unique, here's a simple algorithm (LabVIEW 8.5). (<A href="http://forums.ni.com/t5/LabVIEW/Permute-matrix-columns-to-find-the-matrix-with-biggest-trace/m-p/1045996#M464961" target="_self" rel="nofollow">see also</A>)</P>
<P> </P>
<P><IMG src="http://forums.ni.com/ni/attachments/ni/170/528135/1/permutate.PNG" border="0" align="center" /></P>
<P> </P>
<P style="padding: 0px; margin: 0px;">The <SPAN class="lia-search-match-lithium" style="font-weight: bold; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; color: #333333; line-height: 1.2; background-position: initial initial; background-repeat: initial initial; padding: 0px 2px 0px 2px;">permutation</SPAN> algorithm is from wikipedia:</P>
<HR />
<P><FONT size="1" style="line-height: normal;">For every number k, with 0 = k < n!, the following algorithm generates a unique <SPAN class="lia-search-match-lithium" style="font-weight: bold; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; color: #333333; line-height: 1.2; background-position: initial initial; background-repeat: initial initial; padding: 0px 2px 0px 2px;">permutation</SPAN> of the initial sequence sj, j = 1, ..., n:</FONT></P>
<P style="padding: 0px; margin: 0px;"><FONT size="1" style="line-height: normal;"> </FONT></P>
<P style="padding: 0px; margin: 0px;"><FONT size="1" style="line-height: normal;">function <SPAN class="lia-search-match-lithium" style="font-weight: bold; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; color: #333333; line-height: 1.2; background-position: initial initial; background-repeat: initial initial; padding: 0px 2px 0px 2px;">permutation</SPAN>(k, s) {<BR /> for j = 2 to length(s) {<BR /> swap s[(k mod j) + 1] with s[j]; // note that our array is indexed starting at 1<BR /> k := k / j; // integer division cuts off the remainder<BR /> }<BR /> return s;<BR /> }<BR />NOTE: Indexing in LabVIEW starts at 0, so the code is changed accordingly.</FONT></P>
<HR />
<P style="padding: 0px; margin: 0px;">Note added:</P>
<P style="padding: 0px; margin: 0px;">In LabVIEW 2019 and newer we could accumulate the permutations in a set, eliminating potential duplicates. (<A href="https://forums.ni.com/t5/Discusiones-sobre-Productos-NI/Ejercicio-de-permutaciones/m-p/4059358#M35426" target="_blank" rel="noopener">Example</A>)</P>
<P> </P>Sat, 13 Jun 2020 19:28:12 GMThttps://forums.ni.com/t5/LabVIEW/How-can-I-create-list-of-permutations/m-p/1257110#M528135altenbach2020-06-13T19:28:12ZRe: How can I create list of permutations
https://forums.ni.com/t5/LabVIEW/How-can-I-create-list-of-permutations/m-p/1257116#M528138
<P>I can not resist the opportunity to implement seven hundred year old algorithms, but do not let me interfere with your fun implementing this. altenbach and I had some fun a little while back doing this for letters, see this thread.</P>
<P> </P>
<P><A href="https://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/td-p/1173677" rel="nofollow" target="_blank">http://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/td-p/1173677</A></P>
<P> </P>
<P>I implemented Pandit's method to find the next permutation using only the prior one. This works quite well in situations where you do not want to be carrying around extremely large arrays. If you want all of the values, just use the second VI.</P>
<P> </P>
<P> </P>
<P><IMG src="https://forums.ni.com/ni/attachments/ni/170/528138/1/PermuteColorsImage.PNG" border="0" align="center" /></P>
<P> </P>
<P>Edit: Fancy meeting altenbach here.....</P>Tue, 28 Jan 2014 00:45:16 GMThttps://forums.ni.com/t5/LabVIEW/How-can-I-create-list-of-permutations/m-p/1257116#M528138Darin.K2014-01-28T00:45:16ZRe: How can I create list of permutations
https://forums.ni.com/t5/LabVIEW/How-can-I-create-list-of-permutations/m-p/1257564#M528221
<P>Thanks Guys, its been fun probing around these block diagrams to see what is going on. My maths is not what it was 700 years ago (when i was still at school) so I will use the second post, but thanks to you all for the help.</P>
<P>All the best,</P>
<P>Michael.</P>Thu, 23 Sep 2010 08:24:13 GMThttps://forums.ni.com/t5/LabVIEW/How-can-I-create-list-of-permutations/m-p/1257564#M528221Michael_782010-09-23T08:24:13ZRe: How can I create list of permutations
https://forums.ni.com/t5/LabVIEW/How-can-I-create-list-of-permutations/m-p/2802622#M821835
<P>Hi.</P>
<P> </P>
<P>Both of the solutions presented here output all possible permutations of the same size as the original array. Can they be modified, or is there a different way, to find all possible permutations of a smaller size?</P>
<P> </P>
<P>For example, for the 6 colors, find all 3-color permutations. We know the number of these permutations is perm(6,3) = 120.</P>
<P> </P>
<P>By the way, what I am actually trying to get is the 255,024 permutations you can get selecting 4 elements out of a pool of 24...</P>
<P> </P>
<P>Any suggestions?</P>
<P> </P>
<P>Thanks in advance,</P>
<P> </P>
<P>Alejandro</P>Thu, 03 Apr 2014 03:43:55 GMThttps://forums.ni.com/t5/LabVIEW/How-can-I-create-list-of-permutations/m-p/2802622#M821835AlejandroZepeda2014-04-03T03:43:55Z