Discrete math algorithm - Combinations of combinations of arrays

I've spent more than 3 days now trying to write an algorithm to do this, but can't find a way... That D is discrete structure in college is coming back to haunt me now I guess...
Trying to find an algorithm to generate all combinations, of all combinations, of n arrays. I found a decent class on the net (google: java array combinations) that generates combinations of a single array taken n at a time, and it was simple enought to adapt it to give all combinations from length 1-array.length.
See example below for possible output;
String[] t = {"X","Y","Z"};
String[] r = {"A","B","C"};
String[] j = {"P","Q","R"};
// generate all combinations of all combinations of all arrays
// ex (line breaks for clarity only)
// X, Y, Z, XY, XZ, YZ, XYZ
// A, B, C, AB, AC, BC, ABC
// P, Q, R, PQ, PR, QR, PQR
// XA, XB, XC, XAB, XAC, XBC, XABC
// XP, XQ, XR, XPQ, XQR, XPQR
// YA, YB, YC, YAB, YAC, YBC, YABC
// YP, YQ, YR, YPQ, YQR, YPQR
// XAP, XAQ, XAR, XAPQ, XAPR, XAQR, XAPRQ
// XYZABCP, XYZABCQ, XYZABCR, XYZABCPQ, XYZABCPR, XYZABCQR, XYZABCPQR
// done

Right you are, thanks! The solution was too simple for me to see.
You can just add all elements from t, r
and j in one set and then generate the power
set of it: no need to keep it in multiple arrays.
http://mathworld.wolfram.com/PowerSet.html

Similar Messages

  • Combining multiple arrays into one

    I am sure this is probably really simple to do, but for some reason I just cannot figure it out.  
    I am creating an HTA that will be used to backup terminated employee's PC.  It will scan the drive for the specific file Types chosen and XCopy them up to the server.
    Originally I had the different file types writing into Strings and then just combining those strings.  I was deliminating the entries with a ;.  The issue I ran into is when combining them I have to have a ; in front of the first entry, the issue
    starts if someone only choose one file type.  Then it looks for any file with no extensions, which is a lot.  
    So then I thought I would just put them into their own arrays and then combine those arrays, but this just seems to be above my head.  I cannot wrap my mind around it.  
    Writing it in VBScript.  Here is the a snippet of the section I am working on.  Everything else in the script/HTA works fine. 
    Sub Extensions(strEndUserFolder)
    If Office.checked Then strOfficeExtensions = "doc;docx;docm;xls;xlt;xlm;xlsx;xlsm;ppt;pps;pptx;pptm;ppsx;ppsm;mdb;ldb;one;onetoc2"
    If PDF.checked Then strPDFExtensions = "pdf"
    If SRA.checked Then strSRAExtensions = "rws"
    If Pictures.checked Then strPictureExtensions = "bmp;jpg;jpeg;gif;tiff;png"
    If Videos.checked Then strVideoExtensions = "mp4;mov;mpeg;mpg;wmv;mov"
    If Notes.checked Then strNotesExtensions = "id"
    If CADUG.checked Then strCADUGExtensions = "dwg;dwt;dxf;dwf;dst;prt"
    arrOfficeExtensions = Split(strOfficeExtensions, ";")
    arrPDFExtensions = Split(strPDFExtensions, ";")
    arrSRAExtensions = Split(strSRAExtensions, ";")
    arrPictureExtensions = Split(strPictureExtensions, ";")
    arrVideoExtensions = Split(strVideoExtensions, ";")
    arrNotesExtensions = Split(strNotesExtensions, ";")
    arrCADUGExtensions = Split(strCADUGExtensions, ";")
    arrExtensions =
    Call SetDrivetoScan(arrExtensions, strEndUserFolder)
    End Sub

    Wow!  A hash table in VBScript would be a great extension.
    Sounds like a job for "ta-da!" ... Array Man!.
    Sub Extensions(strEndUserFolder)
    ext=""
    If Office.checked Then ext=ext & "doc;docx;docm;xls;xlt;xlm;xlsx;xlsm;ppt;pps;pptx;pptm;ppsx;ppsm;mdb;ldb;one;onetoc2;"
    If PDF.checked Then ext = ext & "pdf;"
    If SRA.checked Then ext = ext & "rws;"
    If Pictures.checked Then ext = ext & "bmp;jpg;jpeg;gif;tiff;png;"
    If Videos.checked Then ext = ext & "mp4;mov;mpeg;mpg;wmv;mov;"
    If Notes.checked Then ext = ext & "id;"
    If CADUG.checked Then ext = ext & "dwg;dwt;dxf;dwf;dst;prt;"
    If Right(ext,1) = ";" Then
    ext = Left(ext,Len(ext) -1 )
    End If
    arrExtensions = Split(ext,";")
    SetDrivetoScan arrExtensions, strEndUserFolder
    End Sub
    Just add them up and remove the last extra one if it exists.
    ¯\_(ツ)_/¯

  • Discrete PID algorithm for digital final control elements

    Is there a Discrete PID algorithm for digital final control element?  This is used to turn on one digital output for a positive move and another digital output for a negative move.

    Good day APCO, I hope all is well.
    I have a couple of questions for you. Are you using LabVIEW? And if you are what version? Also, are you using any toolkits or modules.
    I know that there is a Discrete PID VI in the FPGA module. Here is the link to some information about that specific VI.
    http://zone.ni.com/reference/en-XX/help/371599A-01/lvfpga/discrete_pid/#details
    If you are not using the FPGA module, we have a PID Toolkit that contains a myriad of VIs. Here is the link for the PID Toolkit.
    http://www.ni.com/toolkits/lv_pid_control.htm#des
    http://www.ni.com/pdf/manuals/322192a.pdf
    Please take a look at the information and let me know if you have further questions. Have a great day.
    Efosa O.

  • How do I combine two arrays into one?

    I am trying to combine two byte arrays into one. What function do I use that will put in the information in the same order just combined?

    battler. wrote:
    Julien,
    Used LV for years.  Never knew that (concatenate inputs).  Wouldn't believe the lengths ive used to get around it.  Thanks
    Same here! I actually learned about it taking a sample test for the CLAD.
    Richard

  • Combining string array elements into one string

    Right, I have an string array called str which stores 1 character in each of its 16 elements. It gets this character from another array, strArray. Now, what I want to be able to do is to take all 16 elements and combine them into one string called keyString. Using the code below keyString only prints out the last character. The code is shown below:
    for (x=0; x<16; x++) {
         str = new String[16];
         str[x] = "";
         str[x] += (strArray[(index+x)%16].charAt(strChar[x]));
         keyString = str[x];
           System.out.print(keyString);
    }Any help would be very much appreciated.
    Edited by: Paragon96 on May 20, 2008 7:32 AM

    your logic is wrong ; if you want to concatenate the content of the array, you have to loop (what you did), and concatenate keyString for each index, meaning:
    keyString += str[x];you can also use a StringBuilder for such kind of operations

  • How can i combine an array of string and an array of integers ?

    i have an array of string data [to be used as header], and an array of multiple column integer vakues;i need them together in one file. 
    Am not able to combine them so that i can write them into a single file.
    Solved!
    Go to Solution.
    Attachments:
    string file input.txt ‏1 KB
    Test build_1.vi ‏13 KB

    There are a few ways you can do this.  What I recommend is:
    Open the file
    Use the Array to Spreadsheet String to turn your headers into a single string
    Write this to the file.
    Use the Array to Spreadsheet String to turn your numeric data into a single string
    Write this to the file.
    Close the file
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • How to combine two arrays?

    HI. Can anyone help me?I need to make waveform graph that shows channels' on and off states. I have done a program which works fine for one channel. Now I want to have the other channel in the same picture. I just can't plot those two signals in same picture. Is there any way to combine these two arrays so line 1 would show channel 1 state and line 2 would show channel 2 state? And it would be great if those extra lines wouldn't show at all in the chart. I know I should some how move bits of one array to the other array,but it should remain 1-D. I attach the code here. If there is(and I bet there is) a better way to do this,  please tell me.
    Mika
    Attachments:
    Channelsstate.vi ‏31 KB

    Would this do?
    Message Edited by devchander on 02-06-2008 04:44 AM
    Attachments:
    dig_graph_21.vi ‏16 KB

  • How to combine different array/cluster sizes in one X-Y graph

    Hi,
    I'm working on a project to analyse hysteresis loops and have come up with three X-Y graphs which give me the information I need. However, I would like to be able to overlay the plots on top on one another. They all have the same axes (load and displacement), but different content:
    1. "Load-Displacement" is a cluster of two 1D arrays (length is variable depending on the data file - in the dummy file attached it is 6369 points)
    2. "Stiffness" is a cluster of two 1D arrays (always 2 points in length)
    3. "Rectangles" is a 1D array of a cluster of two 1D arrays (length dependent on the number of rectangles which is determined by the number of times the FOR loop is executed - default is 100)
    Can someone point me in the right direction - I'm sure there must be an easy way, but haven't found it in the help file/searches/forums
    Many thanks,
    Ian
    Solved!
    Go to Solution.
    Attachments:
    Hysteresis loop analysis.vi ‏191 KB
    dummy data full.txt ‏258 KB

    Something like this
    Tim
    Johnson Controls
    Holland Michigan
    Attachments:
    Example.vi ‏184 KB

  • Best algorithm to sort semi-sorted arrays?

    I am trying my hand at the hutter prize (http://prize.hutter1.net/)
    My current compression algorithm sorts an array of Comparable Objects every main cycle.
    -This array of objects can potentically increase by one object per cycle.
    -Each object's comparision value can change per cycle, however its order is mostly kept.
    This means that the over all order of the objects are similar between cycles.
    Is there an sorting algorithm which can take advantage of the semi-sorted state of the array?
    I was using the default Arrays.sort() however it does not seem to make much use of the semi-sorted input array and is too slow for my use.
    In order to speed up the sorting i have relaxed the need to be in strict order. I.e there can be some objects out of order.
    To this end I have developed a BucketSort which i thought should speed up the sorting however it seems to have the opposite effect!
    Is there any reason why this implementation is quite slow? (three times as slow as Array.sort() )
       private static int MAX_BUCKET=65535;
       private static Word[] buckets=new Word[MAX_BUCKET];
       public static void bucketSortReverse (Word[] a, int n)
            int i;
            int count=1;
            int index;
            Word curr;
            // fill up the buckets with the input words
            for (i=0;i<n;i++)
                 curr=a;
              index=(int) (curr.probablility*MAX_BUCKET);
              curr.next=buckets[index];
              buckets[index]=curr;
         // iterate over the buckets and construct the sorted words
         for (i=0;i<MAX_BUCKET;i++)
              curr=buckets[i];
              if (curr!=null)
                   while (curr!=null)
                        a[n-count++]=curr;
                        curr=curr.next;
                   buckets[i]=null;
    NOTE Currently my input Word array contains a maximum of 6000 words.
    Lowering the number of bins reduces the accuraccy of the sort and does not provide much increase in speed :(
    I have found some Open Source code which by default performs very similarly to Arrays.sort in terms of speed and have modified it to be non-strict in its ordering.
    This modified sorting algothim is approximately 15% faster but is still really not fast enough.
    By reducing the strict ordering of the sorting algorithm i have also reduced the level of compression. Ultimately i would like to have a fast sorting algothrim which takes into acount semi-sorted objects with out reducing strictness of the sort.
    Any ideas?

    Tree removal takes O(logn) and insertion takes O(logn). Compare this to an array where potentially a large number of elements need to be shifted O(n).
    Usually it takes hundreds of thousands of elements to notice a difference. So if your data is relatively small, then it may not be worth trying to optimize it.
    test of the parent may need to be performed to determine The balanced binary tree (TreeSet) that comes with the JDK doesn't allow access to the internal structure of the tree, so testing the parent isn't available. Even if it was, it would still take an O(logn) lookup to find the node and get its parent, so it wouldn't be a significant improvement.

  • Combining Array Collections

    What's the best way to combine two array collections to make a 3rd array collection?
    loop through all the elements of AC1 and AC2 and addItem to AC3? or is there something an easier/elegant way of going about it...?
    AC1 bound to 1 list, AC2 is bound to another list both have different data in them but contain the same fields...

    Hi SpaghettiCoder,
    You can loop through all the elements of AC1 and AC2 and addItem to AC3. However below is the easiar method to follow:
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="combineArrayCollections()">
    <mx:Script>
      <![CDATA[
       import mx.collections.ArrayCollection;
       private var ac1:ArrayCollection = new ArrayCollection([{label:"1",data:1},{label:"2",data:2},{label:"3",data:3},{label:"4",data :4}])
       private var ac2:ArrayCollection = new ArrayCollection([{label:"5",data:5},{label:"6",data:6},{label:"7",data:7},{label:"8",data :8}])
       private var combineArrayCollection:ArrayCollection;
       private function combineArrayCollections():void
        combineArrayCollection = new ArrayCollection((ac1.source as Array).concat((ac2.source as Array)));    
      ]]>
    </mx:Script>
    </mx:Application>
    If this post answers your question or helps, please kindly mark it as such.
    Thanks,
    Bhasker Chari

  • How to combine indicators in different cases?

    I had a case structure, with different functional array indicators having the same size (21X21) in each case.
    Is there any way to combine these array indicators into just 1?
    Thanks!
    BR

    In the "line case," I didnt expect any chane in those 5 loop  That loop was for the following 2 cases.
    The main difficulty I encountered was that the I didnt know how to show the marquee with different times of loop.
    As you might see, the line case was supposed to be 21 stages, while the rectangle and circle were only 5.
    Thx ur help again 

  • Merging Arrays and Grouping

    Hi guys,
    I am trying to write an algorithm to merge an array of objects to cut down its size. Easier to understand by example.
    Lets say I have 3 numbers , 1, 2 and 3. And 3 elements. So I want to create all combination's of these numbers. Like :
    1,1,1
    1,1,2
    1,1,3
    1,2,1
    1,2,2
    1,2,3
    1,3,1
    etc..
    Then lets say I only had removed some of the combinations and was left with :
    1,1,1
    1,1,2
    1,1,3
    1,2,1
    1,2,2
    1,3,1
    1,3,2
    1,3,3
    I would want this shortened to :
    1,1,=
    1,2,1
    1,2,2
    1,3,=
    (= meaning all possible numbers, in this case 1 2 and 3)
    Also if I had :
    1,1,1
    1,1,2
    1,1,3
    1,2,1
    1,2,2
    1,2,3
    1,3,1
    1,3,2
    1,3,3
    2,1,1
    This would be shortened to :
    1,=,=
    2,1,1
    And if I had :
    1,1,1
    1,1,2
    1,2,1
    1,2,3
    1,3,1
    This would be shortened to :
    1,=,1
    1,1,2
    1,2,3
    I think you'll get the idea from that. There could be more that 3 elements. I have been trying to work this out but its doing my head in.
    Would be grateful if anyone could give me and tips or point me in the right direction.
    Thanks.
    Edited by: joeJack on Mar 1, 2010 12:21 PM
    Changed from asterisk to equals sign as asterisk was creating bold text.

    Hi
    My suggested Algorithm is: Take a LinkedHashSet and put all possible combinations of merged objects from the number of elements. From your example all possible combination is 1==,2==,3==,11=,12=,13=,21=,22=,23=,31=,32=,33=. with all values 0(zero). Keep in mind that most general combination will be kept first like,1== and most specific at last i.e 12=,13=...etc
    Now scan the each element one by on from array and if first character is 1 of the element increase the count of 1== by 1, if second character is 2 i.e element of the form 12 then increase the count of 12= by 1..and so on till last -1 character of the element.So that way we calculate the frequency of each element in on go.
    Now check the number of the count for each element. Say for 1== count is 5 and we know that for 1== count has to be 9 (from permutation possible value 3* 3=9). Similarly go and check each element count and those element count which match the possible permutation value criteria they will be replace by that combination.
    if array sixe is >>> than no of character in one string than this algorith will run ~~ n time where n size of array.

  • Adding large arrays to a text file as new columns

    I am trying to merge several large text data files into a single file in Labview 8.0.  The files are too large to read in all at once (9-15 million lines each), so decided I need to read them in as smaller chunks, combine the arrays, and write them to a new file.
    The reason there are three separate data files was for speed and streaming purposes in the project, and the users wanted the raw, unadulterated data written to file before any kind of manipulation took place. 
    My VI:
    1.  Takes a header generated from another VI and writes it to the output file.
    2.  Creates a time column based on sample rate and the total number of data points
    3.  Reads in 3 files that each have text data (each data point is 9 bytes wide, there are up to 15 million data points per file.
    4.  Each iteration of the for loop writes a chunk of 10 to 100 thousand points (Somewhere in there seems to be the fastest it will do), formatted with the time column on the left, then the three data columns, until it's done.  I haven't quite figured out how to write the last iteration if there are fewer data points than the chunk size.
    Anyways, the main thing I was looking for was suggestions on how to do this faster.  It takes about a minute per million points on my laptop to do this operation, and though I recognize it is a lot of data to be moving around, this speed is painfully slow.  Any ideas?
    Attachments:
    Merge Fast Data.vi ‏67 KB

    Thanks for the tip.  I put the constants outside the array and noticed a little improvement in the speed.  I know I could improve the speed by using the binary file VI's but I need the files as tab delimited text files to import them into MATLAB for another group to do analysis.  I have not had any luck converting binary files into text files.  Is there an easy way to do that?  I don't know enough about binary file systems to use them.  I looked at the high speed data logger examples but they seemed complicated and hard to adapt to what I need to do.  Creating the binary header file seemed like a chore. 
    I am up for more advice on the VI I posted, or suggestions on different ways to convert a binary file to a MATLAB readable text file.
    Thanks!

  • How do we save three 1D arrays in while loop as an excel file? I used build array, waveform. I could not make it work.

    I have three separate 1 dimensional arrays in a while loop. I need to combine these arrays and save as a excel file outside the loop.
    My second question is that is there any emergency STOP button in Labview so that when I press that button, it cuts all the power going to the system. Thanks...

    Just a comment on the Stop button.
    It's not really a good idea to rely solely on a software emergency shutdown. Especially if the shutdown is to prevent some type of hazardous condition to the people running the test. The problem is that if your application or PC in general is having some type of problem, it may not be able to shut everything down as needed.
    You should always have a mechanical �Big Red Stop Button� that you can hit to cut power to everything. In addition to the button, I usually do have LabVIEW monitor things and if conditions are not looking good, have it automatically shut things down. This has always worked good, and I can�t remember any time I�ve actually had to use the big button, but it�s nice to know it�s there.
    VERY IMPORT
    ANT:
    Using the �Abort� button on the LabVIEW toolbar is NOT the thing to do. This stops your application where ever it is in its execution and does not allow it to finish or execute any shutdown code you might have put in. A �Kill� button on the front panel works well. I�ve put a single Boolean terminal in its own little While loop to monitor it. It usually writes to a digital line that�s holding a relay on that will cut the power.
    Ed
    Ed Dickens - Certified LabVIEW Architect - DISTek Integration, Inc. - NI Certified Alliance Partner
    Using the Abort button to stop your VI is like using a tree to stop your car. It works, but there may be consequences.

  • Selecting one period from array (array data selection)

    Hello. I have mass spectrometer which gives me two analog signals (can be seen on attached Data.png picture). The black one is RAMP, which represents nucleous mass number and the red one is intensity of the atom with correspond mass number (in VI I simulate it with signal generators). The data flow from spectrometer is continuous without any timing.
    What I am trying to do is measure N samples from both analog channels and do a data proccesing with them:
    1. Find and separate one measurement period
    2. Convert the period points to amount of actually measured mass (eg I measure nucleous number from 1 to 20, so there will be array of 20 indexes in the end)- that I do in FOR loop
    3. Take another measurement and combine with previous to do a statistical processing (not implemented in VI yet)
    The biggest problem I seem to have is with correct separation of measurement period. I have tried use "min max" function, but there is not always global minimum and maximum at array indexes where I need to. Could you please help me with that separation? Thanks.
    Solved!
    Go to Solution.
    Attachments:
    Data.png ‏30 KB
    LV2.vi ‏191 KB

    Thank you for revision. The final while loop is preparation for another data processing (the measurement will be done more, than once and then I combine output array results for some statistics). "Period" is wrong word you are right , it is more likely some "measurement period" of my spectrometer.
    There was one more bug- the number of subarrays. Instead of (+) there has to be (-). Now it gives more reliable Output result.
    Do you think is it better to use MEAN, or MEDIAN function in for loop? I think in case of spectrometer, median will be more accurate. What is your opinion?
    Attachments:
    LV4.vi ‏78 KB

Maybe you are looking for

  • How can we assign an action triggered by an event to a Background job?

    Hi All,         At the moment we are having an on click action event "EXECUTE"  [GSACTIONS/ActionOV ->eh_onexecute] , on click of this event , it is triggering a BADI which has a rewritten method "IF_EX_EXEC_METHODCALL_PPF~EXECUTE" in which we have o

  • Problem in total PO qty in print out of PO

    Hi Gurus, I'm creating a PO with discount for example i use HB01 (header discount) the original PO qty is 10 pcs after saving and printing of PO the PO qty only show 1 pc only, can u tell me why these happen? can you suggest a solution to fixed these

  • Photoshop CS4 won't print on a new Canon Pixma Pro 10 - Mac Yosemite -

    New Epson Pixma Pro 10. Printer works well with other applications, but just sends out blank pages when printing from Adobe Photoshop CS4. Canon suggested I use their plug, Print Studio Pro, and this worked with a file with layered images and text. H

  • How to enable Custom Objects in offine edition of CRM On Demand

    Hi, We need to enable Custom Objects in the offline edition of CRM On Demand so that Sales Reps can capture the additional information while they are in the field. I wanted to know how do we enable the Custom Objetcs in the offline edition. Any point

  • Distinct distribution query

    Hi all, I have the next records table example: WITH taba      AS (SELECT 2000 AS id, 'ORDEM' AS name, 'FILEA' AS description FROM DUAL          UNION ALL          SELECT 2000 AS id, 'ORDEM' AS name, 'FILEB' AS description FROM DUAL          UNION ALL