topic Re: permutations of a 6! numerically in LabVIEW
https://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1173835#M510620
<P>Then you're challenged! <span class="lia-unicode-emoji" title=":winking_face:">ðŸ˜‰</span></P>Thu, 08 Jul 2010 12:58:54 GMTJohn Pierson2010-07-08T12:58:54Zpermutations of a 6! numerically
https://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1173677#M510581
<P>I'm trying to build a VI that lets me use the letters A B C D E F and arrange them in all permutations (so 720 different orders - 6!)</P>
<P>i've tried doing it with simple N-loop structures, but i'm a bit rusty.</P>
<P> </P>
<P>the output would ideally be a 2D word matrix of</P>
<P> </P>
<P>ABCDEF</P>
<P>ABCDFE</P>
<P>etc......</P>
<P> </P>
<P>help!!</P>Thu, 08 Jul 2010 10:52:49 GMThttps://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1173677#M510581John Pierson2010-07-08T10:52:49ZRe: permutations of a 6! numerically
https://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1173739#M510591
<P>oh, i'm on LV v8.2</P>Thu, 08 Jul 2010 12:07:27 GMThttps://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1173739#M510591John Pierson2010-07-08T12:07:27ZRe: permutations of a 6! numerically
https://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1173747#M510593
<P>Hi John,</P>
<P>maybe this hepls.</P>
<P><A href="http://zone.ni.com/devzone/cda/epd/p/id/362" rel="nofollow" target="_blank">http://zone.ni.com/devzone/cda/epd/p/id/362</A></P>
<P> </P>
<P>Mike</P>Thu, 08 Jul 2010 12:14:26 GMThttps://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1173747#M510593MikeS812010-07-08T12:14:26ZRe: permutations of a 6! numerically
https://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1173757#M510596
<P>i believe that one only gives you the number of permutations, what I'm after is the permutations in total as a list.</P>Thu, 08 Jul 2010 12:17:24 GMThttps://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1173757#M510596John Pierson2010-07-08T12:17:24ZRe: permutations of a 6! numerically
https://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1173761#M510598
<P>Hi John,</P>
<P>if you can wait some hours, then i upload an example later (i don't have it with me now).</P>
<P> </P>
<P>Mike</P>Thu, 08 Jul 2010 12:19:26 GMThttps://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1173761#M510598MikeS812010-07-08T12:19:26ZRe: permutations of a 6! numerically
https://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1173763#M510599
<P>oh, hang on, i'll give it a go, need to turn on the pc with LV on it to check</P>
<P> </P>Thu, 08 Jul 2010 12:19:24 GMThttps://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1173763#M510599John Pierson2010-07-08T12:19:24ZRe: permutations of a 6! numerically
https://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1173769#M510602
<P>@Mike, i'll give it a go myself, but i would really apreciate an example, i'll upload anything i get if i make progress.</P>
<P>Chears for you help!</P>Thu, 08 Jul 2010 12:20:45 GMThttps://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1173769#M510602John Pierson2010-07-08T12:20:45ZRe: permutations of a 6! numerically
https://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1173777#M510605
<P>@Mike - yeah ran it on my other computer, it just does the 'how many permutations are there' calculation</P>
<P>thats not what i'm after, i'm after each of the permutations themselves.</P>
<P> </P>
<P>so lets say we have A B C D E and F</P>
<P> </P>
<P>so it could start:-</P>
<P> </P>
<P>ABCDEF</P>
<P>ABCDFE</P>
<P>ABCEDF</P>
<P>ABCEFD</P>
<P>....</P>
<P>and so on, its a simple enough sequence its just laborious to type out 720 lines of it manually,</P>
<P>and i'f i move onto 7,8 or 9 letters gets longer and longer.</P>Thu, 08 Jul 2010 12:30:22 GMThttps://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1173777#M510605John Pierson2010-07-08T12:30:22ZRe: permutations of a 6! numerically
https://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1173791#M510610
<P>Hi John,</P>
<P>i understand what you need, but i didn't open the example from the link. Sorry for that. I'll upload an example later.</P>
<P> </P>
<P>Mike</P>Thu, 08 Jul 2010 12:35:57 GMThttps://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1173791#M510610MikeS812010-07-08T12:35:57ZRe: permutations of a 6! numerically
https://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1173797#M510612
<P>no worries mike, its esentially a sequence its done neatly, you can say the first coloumn- the far left one</P>
<P> </P>
<P>A repeats 24 times, then B 24 times, C- 24 etc......</P>
<P> </P>
<P>The next column over then repeats the remaining letters every 6</P>
<P> </P>
<P>B: 6, C: 6 etc......</P>
<P> </P>
<P>and so on.</P>Thu, 08 Jul 2010 12:41:10 GMThttps://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1173797#M510612John Pierson2010-07-08T12:41:10ZRe: permutations of a 6! numerically
https://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1173805#M510613
<P>This is a good one...</P>
<P> </P>
<P>Would be a nice coding challenge <span class="lia-unicode-emoji" title=":winking_face:">ðŸ˜‰</span> To do it nicely that is...</P>
<P> </P>Thu, 08 Jul 2010 12:45:06 GMThttps://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1173805#M510613Ray.R2010-07-08T12:45:06ZRe: permutations of a 6! numerically
https://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1173835#M510620
<P>Then you're challenged! <span class="lia-unicode-emoji" title=":winking_face:">ðŸ˜‰</span></P>Thu, 08 Jul 2010 12:58:54 GMThttps://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1173835#M510620John Pierson2010-07-08T12:58:54ZRe: permutations of a 6! numerically
https://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1173841#M510621
<P>I built something similar to this once when I was trying to recover a lost password from an Excel spreadsheet (using ActiveX to open the spreadsheet with the new password).</P>
<P> </P>
<P>It worked well, but the password was about 10 characters so I never manager to brute force it!</P>
<P> </P>
<P>Will see if I can dig it up (prob not as it was at a previous employer...)</P>Thu, 08 Jul 2010 13:04:26 GMThttps://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1173841#M510621Neil.Pate2010-07-08T13:04:26ZRe: permutations of a 6! numerically
https://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1173847#M510623
<P>would really apreciate the help if you can find it <span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:">ðŸ˜„</span></P>Thu, 08 Jul 2010 13:06:40 GMThttps://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1173847#M510623John Pierson2010-07-08T13:06:40ZRe: permutations of a 6! numerically
https://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1173853#M510625
<P>Hm, besides that the question itself sounds a bit like: "how do i implement a brute force algorithm using LabVIEW?", i have to ask:</P>
<P>Is the length of the string always equal to the number of possible characters?</P>
<P> </P>
<P>Norbert</P>Thu, 08 Jul 2010 13:10:07 GMThttps://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1173853#M510625Norbert_B2010-07-08T13:10:07ZRe: permutations of a 6! numerically
https://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1173857#M510627
<P>Hi Norbert,</P>
<P>i think it don't have to. <span class="lia-unicode-emoji" title=":slightly_smiling_face:">ðŸ™‚</span></P>
<P> </P>
<BLOCKQUOTE>
<HR /><LI-USER uid="35097"></LI-USER> B wrote:<BR />
<P>... "how do i implement a brute force algorithm using LabVIEW?", i have to ask:</P>
<P>...</P>
<P> </P>
<P>Norbert</P>
<HR />
</BLOCKQUOTE>
<P>Do you think if this is the question, then we shouldn't help and he should write the code himself?? <span class="lia-unicode-emoji" title=":winking_face:">ðŸ˜‰</span></P>
<P> </P>
<P>Mike</P>Thu, 08 Jul 2010 13:17:00 GMThttps://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1173857#M510627MikeS812010-07-08T13:17:00ZRe: permutations of a 6! numerically
https://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1173859#M510628
<P>it is an attempt to break an encryption a friend has sent me. I suspect it is 6 characters long from a hint, i have tried 1 character to 5 by hand to no success, and i thought a program for six, seven etc... would be logical. i was then going to scan for a key word from the resultant decryption - but that bit i've already figured out how to do.</P>
<P> </P>
<P>Six character will be fine for now, seven i hope can be made by expanding the program at a later date if needed.</P>Thu, 08 Jul 2010 13:17:43 GMThttps://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1173859#M510628John Pierson2010-07-08T13:17:43ZRe: permutations of a 6! numerically
https://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1173861#M510629
<P><span class="lia-unicode-emoji" title=":disappointed_face:">ðŸ˜ž</span></P>
<P> </P>
<P>its only a bit of fun, but the output will be handy for my research rather oddly!</P>Thu, 08 Jul 2010 13:18:47 GMThttps://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1173861#M510629John Pierson2010-07-08T13:18:47ZRe: permutations of a 6! numerically
https://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1173863#M510630
<P>Hi John,</P>
<P>why to change it later. The "challenge winner" should be able to handle whatever is needed!</P>
<P> </P>
<P>Mike</P>Thu, 08 Jul 2010 13:19:43 GMThttps://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1173863#M510630MikeS812010-07-08T13:19:43ZRe: permutations of a 6! numerically
https://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1173867#M510632
<P>i think it can be done by perhaps logical sequences, </P>
<P> </P>
<P>IF A is used then character B is true for second character, if not A</P>Thu, 08 Jul 2010 13:25:01 GMThttps://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1173867#M510632John Pierson2010-07-08T13:25:01ZRe: permutations of a 6! numerically
https://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1173869#M510633
<P>Ok, Mike is correct that i should not help you in working out a brute force algorithm <span class="lia-unicode-emoji" title=":winking_face:">ðŸ˜‰</span></P>
<P>Nevertheless, since it is a demanding request, i give you some hints:</P>
<P>a) Handle it in a recursive way</P>
<P>b) The modulo operation (Quotient&Reminder) is your friend</P>
<P> </P>
<P>c) there is a reason why most algorithms do not compute all valid permutations but "roll the dice on it"......</P>
<P> </P>
<P>hope this helps,</P>
<P>Norbert</P>
<P> </P>
<P>PS: If the amount of valid elements would match the number of elements, this request could be solved fairly nicely with building all permutations on purpose. If there is no such match, rolling the dice is coming much more handy......</P>Thu, 08 Jul 2010 13:27:23 GMThttps://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1173869#M510633Norbert_B2010-07-08T13:27:23ZRe: permutations of a 6! numerically
https://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1173871#M510634
<P>Hi all,</P>
<P> </P>
<P>recursion in LV9 is a dream...</P>
<P> </P>
<P>It's not nice, but seems to work. Open Rec_Perm_Main.vi...</P>Thu, 08 Jul 2010 13:31:33 GMThttps://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1173871#M510634GerdW2010-07-08T13:31:33ZRe: permutations of a 6! numerically
https://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1173873#M510635
<P>Hi John,</P>
<P>the algorithm shouldn't be the problem, you can see an example from Delphi here</P>
<P><A href="http://www.swissdelphicenter.ch/torry/showcode.php?id=1032" rel="nofollow" target="_blank">http://www.swissdelphicenter.ch/torry/showcode.php?id=1032</A>.</P>
<P> </P>
<P>I think the more tricky thing is to make it fast. In LabVIEW you should avoid using string arrays to store the results. Much faster is to write it directly into a file.</P>
<P> </P>
<P>Mike</P>Thu, 08 Jul 2010 13:29:10 GMThttps://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1173873#M510635MikeS812010-07-08T13:29:10ZRe: permutations of a 6! numerically
https://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1173889#M510636
<P>hi, can you convert for LV v8.2 please?</P>Thu, 08 Jul 2010 13:37:33 GMThttps://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1173889#M510636John Pierson2010-07-08T13:37:33ZRe: permutations of a 6! numerically
https://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1173891#M510637
<P>cool, can that be used in the matlab window for labview?</P>
<P>-> i'm not to good with the matlab window coding.</P>Thu, 08 Jul 2010 13:39:03 GMThttps://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1173891#M510637John Pierson2010-07-08T13:39:03ZRe: permutations of a 6! numerically
https://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1173899#M510639
<P>Hi John,</P>
<P> </P>
<P>"can you convert for LV v8.2 please?"</P>
<P> </P>
<P>No, it uses Recursion capability of LV2009... Time to upgrade?</P>
<P> </P>
<P>That's the block diagram of the permutation VI:</P>
<P><IMG src="https://forums.ni.com/t5/image/serverpage/image-id/18361i65075F082DF69BEE/image-size/original?v=mpbl-1&px=-1" border="0" alt="18361i65075F082DF69BEE" title="perm.png" align="center" /></P>
<P>"String in" is the string converted to an U8 array, "strings out" will be converted back in the main VI... (And the subVI is the VI itself - Recursion!)</P>
<P> </P>Thu, 08 Jul 2010 13:44:10 GMThttps://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1173899#M510639GerdW2010-07-08T13:44:10ZRe: permutations of a 6! numerically
https://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1173903#M510641
<P>ah damn, now i understand the 'its a dream' i thought you meant 'it didn't work in LV9'</P>
<P> </P>
<P>no stuck with LV 8.2 for now</P>Thu, 08 Jul 2010 13:42:50 GMThttps://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1173903#M510641John Pierson2010-07-08T13:42:50ZRe: permutations of a 6! numerically
https://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1173925#M510644
<P>i guess it become a question of which is easier;</P>
<P> </P>
<P>Build a recursive vi for lv 8.2</P>
<P> </P>
<P>or </P>
<P> </P>
<P>Try the sequence idea </P>
<P> </P>
<P> </P>
<P>I'm sure there is a method in the repeating and holding the already used characters using logic.</P>Thu, 08 Jul 2010 13:55:30 GMThttps://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1173925#M510644John Pierson2010-07-08T13:55:30ZRe: permutations of a 6! numerically
https://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1173941#M510649
<P>Hi John,</P>
<P>you can use the code from Gerd. The only thing you need to do is to load the VI dynamically, then it's possible with recursion.</P>
<P> </P>
<P>Mike</P>Thu, 08 Jul 2010 14:06:44 GMThttps://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1173941#M510649MikeS812010-07-08T14:06:44ZRe: permutations of a 6! numerically
https://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1173973#M510652
<P>sort of copy and paste? or do i need to download their softwere to see it?</P>
<P> </P>
<P>how do you load dynamically - VI run settings?</P>Thu, 08 Jul 2010 14:17:32 GMThttps://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1173973#M510652John Pierson2010-07-08T14:17:32ZRe: permutations of a 6! numerically
https://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1173999#M510656
<P>Hi John,</P>
<P> </P>
<P>look for the "Application Control" functions palette. "Open VI Reference" and "Call by Reference" might be interesting...</P>Thu, 08 Jul 2010 14:25:33 GMThttps://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1173999#M510656GerdW2010-07-08T14:25:33ZRe: permutations of a 6! numerically
https://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1174027#M510658
<P>Can recursion be used for this challenge wiht LV 8.2?</P>
<P> </P>
<P>Somewhere in there we picked-up the option to share clones but without that option, it may blow-up in LV 8.2 due to a lack of memory.</P>
<P> </P>
<P>Ben</P>Thu, 08 Jul 2010 14:39:11 GMThttps://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1174027#M510658Ben2010-07-08T14:39:11ZRe: permutations of a 6! numerically
https://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1174109#M510671
<P>What would be wrong with just using a while loop that counts to 1000000. Convert each iteration to a string, filter out any number with [0,7-9], then do a simple search and replace (1=A, 2=B, etc).</P>
<P> </P>
<P>Of course, it gives you repeat letters and lengths shorter than 6, but those should be easily filtered as well.</P>
<P> </P>
<P>Not elegant or super fast (takes a few seconds to build it to an array, didn't try writing directly to a file), but certainly easy.</P>Thu, 08 Jul 2010 15:07:40 GMThttps://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1174109#M510671jacobdiemer2010-07-08T15:07:40ZRe: permutations of a 6! numerically
https://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1174129#M510674
<P>Its simple, and the filtering would be straight forward,</P>
<P>its not elegant but that would work.</P>
<P> </P>
<P>hmm, nice idea. And it would be easy to see if it worked, run a line count compare to n! for that number and check for repeats and remove.</P>
<P> </P>
<P>That might just do it.</P>
<P> </P>
<P>I'll give it a go! <span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:">ðŸ˜„</span></P>Thu, 08 Jul 2010 15:18:40 GMThttps://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1174129#M510674John Pierson2010-07-08T15:18:40ZRe: permutations of a 6! numerically
https://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1174155#M510679
<P>Here's a quick modification (LabVIEW 8.0), adapted from <A rel="nofollow" href="http://forums.ni.com/t5/LabVIEW/Permute-matrix-columns-to-find-the-matrix-with-biggest-trace/m-p/1045996#M464961" target="_self">this</A> much more complex problem. <span class="lia-unicode-emoji" title=":winking_face:">ðŸ˜‰</span></P>
<P> </P>
<P><IMG src="http://forums.ni.com/ni/attachments/ni/170/510679/1/permutate.png" border="0" align="center" /></P>
<P> </P>
<P><IMG src="http://forums.ni.com/ni/attachments/ni/170/510679/3/permutateFP.PNG" border="0" align="center" /></P>Thu, 08 Jul 2010 15:29:40 GMThttps://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1174155#M510679altenbach2010-07-08T15:29:40ZRe: permutations of a 6! numerically
https://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1174187#M510687
<P>... and here is the same using plain strings:</P>
<P> </P>
<P><IMG src="http://forums.ni.com/ni/attachments/ni/170/510687/1/PermutateString.PNG" border="0" align="center" /></P>Thu, 08 Jul 2010 15:39:45 GMThttps://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1174187#M510687altenbach2010-07-08T15:39:45ZRe: permutations of a 6! numerically
https://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1174189#M510688
<P>sweet, here's hoping it'll run on LV v8.2 <span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:">ðŸ˜„</span></P>Thu, 08 Jul 2010 15:41:18 GMThttps://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1174189#M510688John Pierson2010-07-08T15:41:18ZRe: permutations of a 6! numerically
https://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1174205#M510690
<P>Sorry, down-conversion to 8.0 will get rid of the in-place structure, so the attached 8.0 VI is a bit ugly. To simplify, you can remove the inner while loop without breaking anything.</P>
<P> </P>
<P>Here's the string version as a 2009 VI for those who upgraded.</P>
<P> </P>Thu, 08 Jul 2010 15:46:53 GMThttps://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1174205#M510690altenbach2010-07-08T15:46:53ZRe: permutations of a 6! numerically
https://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1174227#M510696
<P> </P>
<P>Here is a cleaned up 8.0 version:</P>
<P> </P>
<P><IMG src="http://forums.ni.com/ni/attachments/ni/170/510696/2/PermutateString80Clean.PNG" border="0" align="center" /></P>
<P> </P>
<P>of course you need to be careful. Don't use very long strings or it will break because of datatype limitations. <span class="lia-unicode-emoji" title=":winking_face:">ðŸ˜‰</span></P>Thu, 08 Jul 2010 15:56:35 GMThttps://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1174227#M510696altenbach2010-07-08T15:56:35ZRe: permutations of a 6! numerically
https://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1174231#M510698
<P>yup, that does the job perfectly, can even be expanded for 7, 8 etc... itterations.</P>
<P>does waht i needed and more <span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:">ðŸ˜„</span></P>
<P> </P>
<P>now to write to a notpad file <span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:">ðŸ˜„</span></P>Thu, 08 Jul 2010 15:56:21 GMThttps://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1174231#M510698John Pierson2010-07-08T15:56:21ZRe: permutations of a 6! numerically
https://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1174249#M510699
<P>Is it possible to change it from an array of say A B C D E F <SPAN> </SPAN>to a word as in:- ABCDEF as a single element?</P>
<P> </P>Thu, 08 Jul 2010 16:04:06 GMThttps://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1174249#M510699John Pierson2010-07-08T16:04:06ZRe: permutations of a 6! numerically
https://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1174255#M510700
<P> </P>
<BLOCKQUOTE>
<HR /><LI-USER uid="97651"></LI-USER> wrote:<BR />
<P>Is it possible to change it from an array of say A B C D E F <SPAN> </SPAN>to a word as in:- ABCDEF as a single element?</P>
<HR />
</BLOCKQUOTE>
<P>Yes, my second example does that. <span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:">ðŸ˜„</span></P>
<P> </P>Thu, 08 Jul 2010 16:06:30 GMThttps://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1174255#M510700altenbach2010-07-08T16:06:30ZRe: permutations of a 6! numerically
https://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1174263#M510701
<P>extra kudos for you my man!</P>Thu, 08 Jul 2010 16:09:52 GMThttps://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1174263#M510701John Pierson2010-07-08T16:09:52ZRe: permutations of a 6! numerically
https://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1174367#M510717
<P>Very nice solution Christian.</P>
<P> </P>
<P><span class="lia-unicode-emoji" title=":slightly_smiling_face:">ðŸ™‚</span> Many kudos.</P>
<P> </P>Thu, 08 Jul 2010 17:12:52 GMThttps://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1174367#M510717Ray.R2010-07-08T17:12:52ZRe: permutations of a 6! numerically
https://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1174689#M510790
<P>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.</P>
<P> </P>
<P>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.</P>
<P> </P>
<P>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.</P>
<P> </P>
<P><IMG src="https://forums.ni.com/t5/image/serverpage/image-id/18403i9E6A43238BFF8228/image-size/original?v=mpbl-1&px=-1" border="0" alt="18403i9E6A43238BFF8228" title="PermuteLetters.png" align="center" /></P>Thu, 08 Jul 2010 20:53:10 GMThttps://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1174689#M510790Darin.K2010-07-08T20:53:10ZRe: permutations of a 6! numerically
https://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1174721#M510797
<P>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...</P>
<P> </P>Thu, 08 Jul 2010 21:22:22 GMThttps://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1174721#M510797Darin.K2010-07-08T21:22:22ZRe: permutations of a 6! numerically
https://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1174725#M510799
<P>What's the difference between the two attachments?</P>
<P> </P>
<P>EDIT: Nevermind, just saw your new post... <span class="lia-unicode-emoji" title=":winking_face:">ðŸ˜‰</span></P>Thu, 08 Jul 2010 21:23:29 GMThttps://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1174725#M510799altenbach2010-07-08T21:23:29ZRe: permutations of a 6! numerically
https://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1174727#M510800
<P>Post collision earlier.</P>Thu, 08 Jul 2010 21:23:19 GMThttps://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1174727#M510800Darin.K2010-07-08T21:23:19ZRe: permutations of a 6! numerically
https://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1174751#M510804
<P>Looks good. Do you have a link to the algorithm?</P>
<P> </P>
<P>(One minor flaw: an empty string input should probably give an empty array as output.)</P>Thu, 08 Jul 2010 21:44:57 GMThttps://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1174751#M510804altenbach2010-07-08T21:44:57ZRe: permutations of a 6! numerically
https://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1174771#M510811
<P> </P>
<BLOCKQUOTE>
<HR />
altenbach wrote:
<P>(One minor flaw: an empty string input should probably give an empty array as output.)</P>
<HR />
</BLOCKQUOTE>
<P> </P>
<P>Quick fix:</P>
<P>In the TRUE case, check for "empty string?" and wire the output to the tunnel, replacing the boolean diagram constant.</P>Thu, 08 Jul 2010 21:57:22 GMThttps://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1174771#M510811altenbach2010-07-08T21:57:22ZRe: permutations of a 6! numerically
https://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1174775#M510813
<P>Here is Knuth's book.</P>
<P>TAOCP Volume 4 Fascicle 2, Generating All Tuples and Permutations (2005), v+128pp. ISBN 0-201-85393-0</P>
<P>Fascicles 0,1, and 2 are spectacular. In fact, almost anything this guy produces (ie. LaTeX) is fabulous.</P>
<P> </P>
<P>The algorithm is as follows:</P>
<P>0. Sort the array in ascending order</P>
<P>1. Find largest m such that array[m+1] > array[m]</P>
<P>2. Find largest n such that array[n] > array[m]</P>
<P>3. Swap array[n] and array[m]</P>
<P>4. Reverse elements array[n+1...N]</P>
<P>If step 1. fails you have reached final iteration.</P>
<P> </P>
<P>Should add: Step -1: Check for empty string.</P>
<P> </P>
<P>Edit: I was forced to use IE, seemed to lose all linefeeds ala iPhone. Back to Firefox to fix.</P>Thu, 08 Jul 2010 22:03:40 GMThttps://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1174775#M510813Darin.K2010-07-08T22:03:40ZRe: permutations of a 6! numerically
https://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1175387#M510920
<P>Thanks for keeping this thread alive Darin.</P>
<P> </P>
<P>I must admit, I was blown away with the elegance and ease of Altenbach's solution. I had not thought of the Qutient and Remainder approach.</P>
<P>Plus, I must admit that I did look at solutions from other languages, such as C/C++.</P>
<P> </P>
<P>I would have gone along the lines of something like this: (of course, implementing it in LV)</P>
<P> </P>
<P> // This program finds permutations using a recursive method<BR /> // modified Dev C++ from a wonderful article at:<BR /> // <A href="http://www.codeproject.com/cpp/cppperm1.asp" target="_blank" rel="nofollow">http://www.codeproject.com/cpp/cppperm1.asp</A><BR /> <BR /> #include<iostream><BR /> #include<cstring><BR /> <BR /> using namespace std;<BR /> <BR /> void char_permutation(char str[],char append[])<BR /> {<BR /> int length = strlen(str);<BR /> if (length)<BR /> {<BR /> for(int i=0;i<length;++i)<BR /> {<BR /> char* str1 = new char[length+1];<BR /> int cnt;<BR /> int cnt2;<BR /> for(cnt=0,cnt2=0; cnt<length; ++cnt,++cnt2)<BR /> {<BR /> if (cnt == i)<BR /> {<BR /> str1[cnt] = str[++cnt2];<BR /> continue;<BR /> }<BR /> else<BR /> str1[cnt] = str[cnt2];<BR /> }<BR /> str1[cnt] = '\0';<BR /><BR /> int alength = strlen(append);<BR /> char* append1 = new char [alength+2];<BR /> strncpy(append1,append,alength);<BR /> append1[alength] = str[i];<BR /> append1[alength+1] = '\0';<BR /><BR /> char_permutation(str1,append1);<BR /><BR /> delete []str1;<BR /> delete []append1;<BR /> }<BR /> }<BR /> else<BR /> {<BR /> cout << append << endl;<BR /> }<BR /> }<BR /> <BR /> <BR /> int main()<BR /> {<BR /> char str[] = "ABCD"; <BR /> char append[] = "\0";<BR /><BR /> cout << "Original = " << str << endl;<BR /> char_permutation(str,append);<BR /> cout << "Done ........" << endl;<BR /><BR /> cin.get(); // wait<BR /> return 0;<BR /> }</P>Fri, 09 Jul 2010 12:17:12 GMThttps://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1175387#M510920Ray.R2010-07-09T12:17:12ZRe: permutations of a 6! numerically
https://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1175667#M510985
<P> </P>
<BLOCKQUOTE>
<HR /><LI-USER uid="2483"></LI-USER> wrote:<BR />
<P>Thanks for keeping this thread alive Darin.</P>
<P> </P>
<P>I must admit, I was blown away with the elegance and ease of Altenbach's solution. I had not thought of the Qutient and Remainder approach.</P>
<P>Plus, I must admit that I did look at solutions from other languages, such as C/C++.</P>
<P> </P>
<P>I would have gone along the lines of something like this: (of course, implementing it in LV)</P>
<P> </P>
<P> </P>
<HR />
</BLOCKQUOTE>
<P>I am a sucker for questions like this one. By the time I got to it, there were already about 5 or 6 pages, and I see it was actually Norbert who made two excellent points (why do I automatically guess DFGray?). Quotient and Remainder and rolling the dice, both very nice.</P>
<P> </P>
<P>Let's face it, almost everything has been done when it comes to these algorithms, but LV is unique is some ways. I happen to like Knuth's books which give algorithms in terms of some hypothetical programming language. Another common approach is to find a C/C++ implementation like Ray.R's post. I think that a lot is "glossed over" in the parenthetical remark (...implementing it in LV). As you either love or hate, LV has some differences with C/C++. We see a lot of code on the forums that is a butchering of something that is natural in C/C++, so there is still an art to implementing something in LV while maintaining the beauty of the original code. Every so often we are fortunate to find ways that LV is actually more suited to a particular algorithm than C/C++.</P>
<P> </P>
<P>So, in this case I say the challenge doesn't end with the finding of the C++ code, it only begins.</P>
<P> </P>Fri, 09 Jul 2010 14:42:37 GMThttps://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1175667#M510985Darin.K2010-07-09T14:42:37ZRe: permutations of a 6! numerically
https://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1175861#M511027
<P>Hi Darin,</P>
<P> </P>
<P>That's my case exactly. I was looking at a text-based solution instead of a native LabVIEW solution.</P>
<P> </P>
<P>My experience so far with both languages (C/C++ & LabVIEW) is that if I base LabVIEW code on code from C, it does get messy and is not optimized (for LabVIEW).</P>
<P>However, if I code a prototype version of a code in LabVIEW, the resulting C code (from the LabVIEW code) is very nice and refined.</P>
<P> </P>
<P>Moreso, may be the fact that I suffer from Labviola-Lackalitus, which is derrived from Textaphobia-Dementia. </P>
<P> </P>
<P>But I'm not complaining <span class="lia-unicode-emoji" title=":winking_face:">ðŸ˜‰</span></P>Fri, 09 Jul 2010 15:52:01 GMThttps://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1175861#M511027Ray.R2010-07-09T15:52:01ZRe: permutations of a 6! numerically
https://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1175933#M511050
<P>The algorithm I used seems to be bit harder to find these days, since it apparently disappeared from wikipedia (<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 old quote here</A>). Interesting.... <span class="lia-unicode-emoji" title=":slightly_smiling_face:">ðŸ™‚</span></P>
<P> </P>
<P>Seems to be a hot topic, with ~500 revisions since 2007. <span class="lia-unicode-emoji" title=":face_with_open_mouth:">ðŸ˜®</span></P>Fri, 09 Jul 2010 16:17:06 GMThttps://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1175933#M511050altenbach2010-07-09T16:17:06ZRe: permutations of a 6! numerically
https://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1175949#M511056
<P>And I thought you did it from scratch... <span class="lia-unicode-emoji" title=":winking_face:">ðŸ˜‰</span></P>
<P> </P>
<P>Thanks for the link to the original thread. Interesting to read the algorithm from Wiki. Glad you had posted it then. <span class="lia-unicode-emoji" title=":slightly_smiling_face:">ðŸ™‚</span></P>Fri, 09 Jul 2010 16:23:54 GMThttps://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1175949#M511056Ray.R2010-07-09T16:23:54ZRe: permutations of a 6! numerically
https://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1176095#M511089
Sometimes I do things from scratch, but most of the time I do things while scratching my head. Not quite the same <span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:">ðŸ˜„</span>Fri, 09 Jul 2010 17:36:46 GMThttps://forums.ni.com/t5/LabVIEW/permutations-of-a-6-numerically/m-p/1176095#M511089altenbach2010-07-09T17:36:46Z