Fill Array with all possible combinations of 0/1

Hi,
i'm looking for a fast way to fill an array, respectively an int[8], with all possible combinations of 0 and 1 (or -1 and 1, shouldn't make a difference).
I kind of know how to do it using multiple loops but I assume there is a more elegant or at leaster "better" practice.
Thanks,
nikolaus
        static int cnt = 0;
     public static void main(String[] args) {
          int[] element = new int[]{1,1,1,1,1,1,1,1};
          Integer[] x = new Integer[2];
          x[0] = 1;
          x[1] = -1;
          for(int i7:x){
               element[7] = i7;
               for(int i6:x){
                    element[6] = i6;
                    for(int i5:x){
                         element[5] = i5;
                         for(int i4:x){
                              element[4] = i4;
                              for(int i3:x){
                                   element[3] = i3;
                                   for(int i2:x){
                                        element[2] = i2;
                                        for(int i1:x){
                                             element[1] = i1;
                                             for(int i0:x){
                                                  element[0] = i0;
                                                  cnt++;
          }Edited by: NikolausO on Oct 30, 2008 4:21 AM
Edited by: NikolausO on Oct 30, 2008 4:22 AM

pm_kirkham wrote:
No I replied to message number 5. as the ' (In reply to #5 )' above my post indicates, which was in reply to (a reply) to Sabre150's post which wasn't using enhanced loops, nor has any obvious place where you could use that approach to fill the array.
Though you could pass in an array of the values to fill the array with, and loop over those, instead of using 0 or 1, at which point Sabre's approach becomes the same as your OP, but without the manual unrolling:
import java.util.Arrays;
public class NaryCombinations {
public interface CombinationHandler {
void apply (int[] combination) ;
public static void main(String[] args) {
calculateCombinations(new int[]{-1, 0, 1}, 4, new CombinationHandler () {
public void apply (int[] combination) {
System.out.println(Arrays.toString(combination));
public static void calculateCombinations (int[] values, int depth, CombinationHandler handler) {
recursivelyCalculateCombinations(values, 0, depth, handler, new int[depth]);
private static void recursivelyCalculateCombinations (int[] values, int index, int depth,
CombinationHandler handler, int[] combination) {
if (index == depth) {
handler.apply(combination);
} else {
for (int value : values) {
combination[index] = value;
recursivelyCalculateCombinations(values, index + 1, depth, handler, combination);
Which looks to use the same basic approach to the generalization I created shortly after posting the original.
public class Scratch1
     * A 'callback' to be invoked with every combination
     * of the result.
    public interface Callback
         * Invoked for each combination.
         * <br>
         * Each call is passed an new instance of the array.
         * @param array the array containing a combination.
        void processArray(int[] array);
    public Scratch1(final int[] array, final Callback callback, final int... values)
        if (callback == null)
            throw new IllegalArgumentException("The 'callback' cannot be 'null'");
        if (array.length < 1)
            throw new IllegalArgumentException("The array length must be >= 1");
        if ((values == null) || (values.length < 1))
            throw new IllegalArgumentException("The 'values' must have be at least of length 2");
        callback_ = callback;
        values_ = values.clone();
        array_ = array;
    public Scratch1(final int order, final Callback callback, final int... values)
        this(new int[order], callback, values);
     * Generates every possible value and invokes the callback for each one.
    public void process()
        process(0);
     * Internal method with no logical external use.
    private void process(int n)
        if (n == array_.length)
            callback_.processArray(array_.clone());
        else
            for (int v : values_)
                array_[n] = v;
                process(n + 1);
    private final Callback callback_;
    private final int[] values_;
    private final int[] array_;
    public static void main(String[] args) throws Exception
        final Callback callback = new Callback()
            public void processArray(int[] array)
                System.out.println(java.util.Arrays.toString(array));
        new Scratch1(6, callback, 2, 1, 0).process();

Similar Messages

  • Printing all possible combinations of a given word.

    Well I'm supposed to print all possible combinations of a given word(I'm writing this for the benefit of those who might not have guessed this from the subject). I've got some code but its horribly wrong. Could anyone point out any mistakes.
    public class Try
        public void display(String s)
            char ch[]=s.toCharArray();
            for(int i=0;i<ch.length;i++)
                String word="";
                word+=ch;
    char c[]=new char[s.length()];
    for(int j=0;j<ch.length;j++)
    if(ch[j]!=ch[i])
    c[j]=ch[j];
    for(int j=0;j<ch.length;j++)
    for(int k=0;k<ch.length;k++)
    if(c[j]!=c[k])
    word+=c[k];
    word+=c[j];
    System.out.println(word);

    Me and Lucifer have been workin on this program for ages.... we cant quite understand your pseudo code.. could you elaborate a bit more on how it works ??
    Meanwhile this is the dysfunctional program weve managed to come up with so far:
    public class SHAM
        public void display(String s)
            char c[]=s.toCharArray();
            for(int i=0;i<c.length;i++)
                String word="";
                char c1[]=new char[c.length-1];
                int a=0;
                for(int l=0;l<c.length;l++)
                    if(i!=l)
                        c1[a++]=c[l];
                for(int j=0;j<c.length-1;j++)
                    char c2[]=c1;
                    word=c[i]+word;
                    if(j+1!=c.length)
                        char t=c2[j];
                        c2[j]=c2[c2.length-1];
                        c2[c2.length-1]=t;
                    for(int k=0;k<c2.length;k++)
                        word+=c2[k];
                    System.out.println(word);               
    }And this is my coding of your pseudo code:
    public class WordCombo2
        public void combo(String s)
            getCombos(s.toCharArray(), s.length());
        private void getCombos(char[] c,int n)
            if (n==1)
                print(c);
                System.out.println();
            else
                for (int i=0;i<c.length;i++)
                    if (i==0 && i<n)
                        c=c[n-1];
    n--;
    getCombos(c,n);
    c[i]=c[n-1];
    private void print(char c[])
    for (int i=0;i<c.length;i++)
    System.out.print(c[i]+" ");
    I really dont understand how this is supposed to work so i dont know whats wrong :( Im sorry this program is just totally baffling me, and on top of that recursion kind of confuses me.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • All possible combinations of 23 columns in a table.

    Hi,
    We have a table as follows;
    CREATE TABLE ALL_PROD_COMB_TMP
    HDLM_ID NUMBER(10),
    MULTIPATH_ID NUMBER(10),
    TRUE_COPY_ID NUMBER(10),
    UVM_ID NUMBER(10),
    TUNING_ID NUMBER(10),
    CLUSTER_ID NUMBER(10),
    MIDDLEWARE_ID NUMBER(10),
    TAPE_ID NUMBER(10),
    THIRD_PARTY_ID NUMBER(10),
    NAS_ID NUMBER(10),
    HBA_ID NUMBER(10),
    BCM_ID NUMBER(10),
    VOLUME_MIGRATION_VERSION_ID NUMBER(10),
    TIERED_STO_MGR_VERSION_ID NUMBER(10),
    HDPS_ID NUMBER(10),
    SERVER_ID NUMBER(10),
    OS_ID NUMBER(10),
    DWDM_ID NUMBER(10),
    EXTENDER_ID NUMBER(10),
    SWITCH_ID NUMBER(10),
    INTERFACE_ID NUMBER(10),
    HUR_ID NUMBER(10),
    STORAGE_FAMILY_ID NUMBER(10)
    The data in the table is as follows;
    For formatting purpose the table data is shown in transposed form.
    Serial No. Column Name Data Value
    1     HDLM_ID                    377     586               
    2     MULTIPATH_ID               142     357               
    3     TRUE_COPY_ID               1     87     12          
    4     UVM_ID                    89     79               
    5     TUNING_ID               10     9     8          
    6     CLUSTER_ID               3     327     638          
    7     MIDDLEWARE_ID                         
    8     TAPE_ID                    3     47     54          
    9     THIRD_PARTY_ID               3                    
    10     NAS_ID                    12     91     1          
    11     HBA_ID                    300     400               
    12     BCM_ID                    14                    
    13     VOLUME_MIGRATION_VERSION_ID     13     12               
    14     TIERED_STO_MGR_VERSION_ID     1     2               
    15     HDPS_ID                    10     100               
    16     SERVER_ID               3     4               
    17     OS_ID                    2     7               
    18     DWDM_ID                    1                    
    19     EXTENDER_ID               520                    
    20     SWITCH_ID               4                    
    21     INTERFACE_ID               2     1     3     4     
    22     HUR_ID                    2     1     3     4     5
    23     STORAGE_FAMILY_ID          2
    Now we have another table named ALL_PROD_COMB having the same structure as that of ALL_PROD_COMB_TMP. In this ALL_PROD_COMB we need all the possible combinations of all the column values from ALL_PROD_COMB_TMP.
    We tried the following thing;
    insert into
         all_prod_comb (
         hdlm_id           
                                       ,multipath_id           
                                       ,true_copy_id           
                                       ,uvm_id                
                                       ,tuning_id           
                                       ,cluster_id           
                                       ,middleware_id
                                       ,tape_id
                                       ,third_party_id
                                       ,nas_id
                                       ,hba_id
                                       ,bcm_id
                                       ,volume_migration_version_id
                                       ,tiered_sto_mgr_version_id
                                       ,hdps_id
                                       ,server_id
                                       ,os_id                
                                       ,dwdm_id           
                                       ,extender_id           
                                       ,switch_id           
                                       ,interface_id           
                                       ,hur_id                
                                       ,storage_family_id
    select distinct
         a.hdlm_id           
                   ,b.multipath_id           
                   ,c.true_copy_id           
                   ,d.uvm_id                
                   ,e.tuning_id           
                   ,f.cluster_id           
                   ,g.middleware_id
                   ,h.tape_id
                   ,i.third_party_id
                   ,j.nas_id
                   ,k.hba_id
                   ,l.bcm_id
                   ,m.volume_migration_version_id
                   ,n.tiered_sto_mgr_version_id
                   ,o.hdps_id
                   ,p.server_id
                   ,q.os_id                
                   ,r.dwdm_id           
                   ,s.extender_id           
                   ,t.switch_id           
                   ,u.interface_id           
                   ,v.hur_id                
                   ,w.storage_family_id
         from (select hdlm_id from all_prod_comb_tmp) a
    ,(select multipath_id from all_prod_comb_tmp) b
    ,(select true_copy_id from all_prod_comb_tmp) c
                   ,(select uvm_id from all_prod_comb_tmp) d
                   ,(select tuning_id from all_prod_comb_tmp) e
                   ,(select cluster_id from all_prod_comb_tmp) f
                   ,(select middleware_id from all_prod_comb_tmp) g
                   ,(select tape_id from all_prod_comb_tmp) h
                   ,(select third_party_id from all_prod_comb_tmp) i
                   ,(select nas_id from all_prod_comb_tmp) j
                   ,(select hba_id from all_prod_comb_tmp) k
                   ,(select bcm_id from all_prod_comb_tmp) l
                   ,(select volume_migration_version_id from all_prod_comb_tmp) m
                   ,(select tiered_sto_mgr_version_id from all_prod_comb_tmp) n
                   ,(select hdps_id from all_prod_comb_tmp) o
                   ,(select server_id from all_prod_comb_tmp) p
                   ,(select os_id from all_prod_comb_tmp) q
                   ,(select dwdm_id from all_prod_comb_tmp) r
                   ,(select extender_id from all_prod_comb_tmp) s
                   ,(select switch_id from all_prod_comb_tmp) t
                   ,(select interface_id from all_prod_comb_tmp) u
                   ,(select hur_id from all_prod_comb_tmp) v
                   ,(select storage_family_id from all_prod_comb_tmp) w;
    But after looking at the explain plan we had to discard this. Simply not possible. Please help us with some other feasible solution.
    regards,
    Dipankar Kushari.

    Hi,
    That's what I have written while posting. Cartesian is no way possible. But is there any way so that I can find out all possible combination of the following values which is there in a table.
    1 HDLM_ID 377 586
    2 MULTIPATH_ID 142 357
    3 TRUE_COPY_ID 1 87 12
    4 UVM_ID 89 79
    5 TUNING_ID 10 9 8
    6 CLUSTER_ID 3 327 638
    7 MIDDLEWARE_ID
    8 TAPE_ID 3 47 54
    9 THIRD_PARTY_ID 3
    10 NAS_ID 12 91 1
    11 HBA_ID 300 400
    12 BCM_ID 14
    13 VOLUME_MIGRATION_VERSION_ID 13 12
    14 TIERED_STO_MGR_VERSION_ID 1 2
    15 HDPS_ID 10 100
    16 SERVER_ID 3 4
    17 OS_ID 2 7
    18 DWDM_ID 1
    19 EXTENDER_ID 520
    20 SWITCH_ID 4
    21 INTERFACE_ID 2 1 3 4
    22 HUR_ID 2 1 3 4 5
    23 STORAGE_FAMILY_ID 2
    regards,
    Dipankar.

  • Creating a tree of all possible combinations of {a,b,c,d}

    I am an MSc conversion student who is struggling with the initial stages of coding his Association Rule Mining dissertation project.
    I have a TreeNode class, which is in the process of being written.
    The class is designed to create a tree that stores all possible combinations of a Vector alphabet of strings {a,b,c,d}
    Please could somebody explain what my TreeNode class is doing so far?
    I have had a lot of help with this and I can't understand why there are so many vectors and what they all do.
    A few pointers (no sarcastic comments please) would be much appreciated.
    The code so far:
    package treenode;
    import java.io.*;
    import java.util.*;
    public class TreeNode
    public static final String INFO_TEXT ="A program to store a vector of string items a,b,c,d in all their possible combinations into a TreeNode class";
    private Vector alphabet;
    private Vector data; // this IS TreeRootData
    private Vector children;
    public TreeNode(Vector inputAlphabet, Vector inputData)
    // the alphabet and data have already been parsed in.
    this.alphabet = inputAlphabet;
    this.data = inputData;
    System.out.println("Tree node constructed with data "+displayVectorOfStrings(this.data));
    children = new Vector(); // we now construct the Vector of children
    //createChildren();
    public void createChildren()
    if data.length =
    // first check to see whether the current data length is the same
    // as the length of the alphabet
    // if it is then stop here (return;)
    // we loop through the alphabet we have...
    // for each candidate in the alphabet, attempt to create a new child TreeNode
    // with a data Vector that is the same as the data in this TreeNode plus
    // the candidate we are looking at in the alphabet. i.e. add available LHS
    // NB: Do NOT add if the candidate is already in the data. {a,b,a} is wrong!
    // NB: We will check to see whether data is already in the tree at a later stage
    // NB: The new Child TreeNode MUST BE ADDED to the children VECTOR -
    // or it will be lost
    public static String displayVectorOfStrings(Vector vector) //Printing the Vector of Strings
    String vectorText = "{";
    for (int i=0; i<vector.size(); i++)
    vectorText += (String)vector.elementAt(i)+",";
    if (vector.size() > 0) vectorText = vectorText.substring(0, vectorText.length()-1);
    // now we chop off the last element, replacing it with a closing bracket,
    // provided that the Vector is not empty.
    vectorText += "}";
    return vectorText;
    public static void main(String[] args) //main method WITH THE ARGUMENTS PASSED IN.
    // This main class can be thought of as OUTSIDE the TreeNode class. Although
    // it is in the file called TreeNode.java it is only here for convenience.
    // This is the top level of the program where everything starts. It is here -
    // that the alphabet is hardcoded in and that the Tree root is constructed.
    displayHeading();
    Vector alphabet = new Vector(); // constructing an initial alphabet,
    alphabet.addElement("a"); // which will eventually come from the database
    alphabet.addElement("b");
    alphabet.addElement("c");
    alphabet.addElement("d");
    System.out.println("Alphabet set to be "+TreeNode.displayVectorOfStrings(alphabet));
    // the root's initial data is now made into an empty Vector...
    Vector initialData = new Vector();
    // the root can now be constructed
    TreeNode treeRoot = new TreeNode(alphabet, initialData); // the treeRoot constructor
    public static void displayHeading()
    System.out.println();
    System.out.println(INFO_TEXT);

    I don't remember from which site I took this material.
    You read this to find all possible combination of a set {a,b,c,d}
    Consider three elements A, B, and C. It turns out that for n distinct elements there are n! permutations possible. For these three elements all of the possible permutations are listed below:
    ABC, ACB, BAC, BCA, CAB, CBA
    Since there are 3 elements there are 3! = 6 permutations possible.
    Suppose instead of A, B, and C you have a deck of 52 playing cards. There are 52! permutations possible (i.e., the number of different ways the cards could be shuffled). Since 52! = 8x10^67, you will need to play a lot of cards before you have seen every permutation of the deck! Since shuffling the deck is a random process (or it should be), each of these 52! permutations is equally likely to occur.
    Developing a non-recursive algorithm to generate all permutations of n elements is a non-trivial task. However, developing a recursive algorithm to do this requires only modest effort and this is what we will do next.
    1. Let E = {e1, e2, ..., en } denote the set of n elements whose permutations we are to generate.
    2. Let Ei be the set obtained by removing element i from E.
    3. Let perm(X) denoted the permutations of the elements in the set X.
    4. Let ei.perm(X) denote the permutation list obtained by prefixing each permutation in perm(X) with element ei.
    Consider the following example, which is provided to clarify the definitions given above:
    If E = {a, b, c}, then E1 = {b, c} since the element in position 1 has been removed from E to create E1. Perm(E1) = (bc, cb) since these are the only two possible permutations of the two elements which appear in E1. Finally, e1.perm(E1) = (abc, acb) which should be apparent from the value of e1 and perm(E1) since the element a is simply used as a prefix to each permutation in perm(E1).
    Given these definitions, we set the recursion base case when n = 1. Since only one permutation is possible for one element, perm(E) = (e) where e is the lone element in E. When n > 1, perm(E) is the list e1.perm(E1) followed by e2.perm(E2) followed by e3.perm(E3) � followed by en.perm(En). This recursive definition of perm(E) defines perm(E) in terms of n perm(X)s, each of which involves an X with n � 1 elements. Thus both the base component and the recursive component (of a recursive algorithm) have been established and we thus have a complete recursive technique to generate the permutations.
    The following Java method is an implementation of this recursive definition of perm(E). This method will output all permutations whose prefix is list[0:k-1] and whose suffixes are the permutations of list[k:m]. By invoking the method with Perm(list, 0, n-1) all n! permutations of list[0: n-1] will be produced. [This is because this invocation will set k = 0 and m = n � 1, so the prefix of the generated permutations is null and their suffixes are the permutations of list[0: n-1]. When k = m, there is only one suffix which is list[m] and list[0: m] defines a permutation that is to be produced. When k < m, the else clause is executed.
    In the algorithm, let E denote the elements in list[k: m] and let Ei be the set obtained by removing ei = list[i] from E. The first swapping sequence in the for-loop has the effect of setting list[k] = ei and list[k+1: m] = Ei. Therefore, next statement which is the call to perm computes ei.perm(Ei). The final swapping sequence restores list[k: m] to its state prior to the first swapping sequence (the state is was in before the recursive call occurred).
    public static void perm(Object [] list, int k, int m)
    {    //generate all permutations of list[k:m]
    int i; Object temp;
    if (k == m) //list has one permutation � so output it
    {      for (i = 0; i <= m; i++)
    System.out.print(list);
    System.out.println;
    else //list has more than one permutation � so generate them recursively
    for (i = k; i <= m; i++)
    {     temp = list[k]; //these next three lines are a simple swap function
    list[k] = list[i];
    list[i] = temp;
    perm(list, k+1, m); //the recursive call
    temp = list[k]; //reset the order in the list
    list[k] = list[i];
    list[i] = temp;
    }//end for-loop
    } //end method perm
    See the program pasted below that prints all possible combination of a set {a,b,c,d}
    public class Perm
    public Perm()
    public static void main(String[] args)
    String s = "abcd";
    char [] chars = s.toCharArray();
    perm(chars, 0);
    public static void perm(char [] list, final int k)
    int i;
    char temp;
    if (k == list.length-1) //list has one permutation, so output it
    for (i = 0; i <= list.length-1; i++)
    System.out.print(list[i]);
    System.out.println();
    else { //list has more than one permutation, so generate them recursively
    for (i = k; i <= list.length-1; i++)
    temp = list[k]; //these next three lines are a simple swap function
    list[k] = list[i];
    list[i] = temp;
    perm(list, k+1); //the recursive call
    temp = list[k]; //reset the order in the list
    list[k] = list[i];
    list[i] = temp;
    }//end for-loop

  • All possible combinations of a column as applied to a unique entry?

    i am having trouble getting a loop to do what i want, if you
    can help me find out what i am doing wrong i would appreciate it:
    i have a database with 3 tables in it
    table 1 has a list of documents - each one having a primary
    key
    table 2 has a list of document properties, i will call them
    property A, B, and C - each one having a primary key
    table 3 is a "relational" table that has a column for a
    document's PK and a property's PK that that document has
    Example of table 3:
    docPK / propPK
    1 (Document 1) / 1 (A)
    2 (Document 2) / 1 (B)
    3 (Document 3) / 2 (B)
    1 (Document 1) / 2 (B)
    1 (Document 1) / 3 (C)
    i need to create a loop in ColdFusion that spits out the
    number of possible combinations that exist for each document
    so the correct output should look like:
    Property A
    Document 1
    Property B
    Document 1
    Document 2
    Document 3
    Property C
    Document 3
    Property A, Property B
    Document 1
    Proberty A, Property B, Property C
    Document 1
    this output displays all possible combinations of properties
    under the conditions of existing documents
    here is the loop i have so far that does not seem to be
    working for me,
    <cfoutput query="rsProperties">
    <ul>
    <cfloop from="0" to="# of properties per document"
    index="i">
    <li>
    <cfoutput group="propPK">
    <cfif i EQ "# of properties per document">
    [#Trim(propertyName)#]
    </cfif>
    </cfoutput>
    </li>
    <ul>
    <cfoutput group="docPK">
    <li><a href="">#Document
    Name#</a></li>
    </cfoutput>
    </ul>
    </cfloop>
    </ul>
    </cfoutput>
    my loop returns possible combinations, but it is not
    returning ALL possible combinations, for example it may only return
    Property A as a single instead of also returning singles Property B
    and C
    my query simply consists of a SELECT * FROM [the database]
    WHERE [the three tables are set equal (as a join)] AND WHERE
    [documents exist]
    i know this is all rather confusing but if you can help me
    make sense of it i will be grateful
    thanks for your time

    Read the cfoutput section of the cfml reference manual. If
    you don't have one, the internet does.
    Look for the example that shows you how to use the group
    attribute.

  • Generating all possible combinations question

    i'm trying to generate all possible combinations for several single column tables each with one string column.
    so - if table 1 has values (aa, ab, ac)
    table 2 has values (zz, zx)
    table 3 has values (qw, qe)
    the result set would contain all possible combinations:
    aa, ab, ac, zz, zx, qw, qe, aazz, aazx, aaqw, aaqe, aazzqw, aazzqe, aazxqw, aazxqe...etc.
    I've tried cross joins - but that does not get the smaller combinations.
    I've looked at some code examples but they seem to be focused on single letter or number combinations.
    I need to do this using tsql.
    code examples or links to such would be of much help.
    Thanks.

    Something like this might work:
    with t1 as (
    select val from table1
    union all
    select ''
    ), t2 as (
    select val from table2
    union all
    select ''
    , t3 as (
    Select val from table3
    union all
    select ''
    select t1.val + t2.val + t3.val
    from t1 cross join t2 cross join t3
    Russel Loski, MCT, MCSE Data Platform/Business Intelligence. Twitter: @sqlmovers; blog: www.sqlmovers.com

  • Where can I get complete INSTANCECONFIG file with all possible tags?

    Can any one provide me the complete instanceconfig file with all possible tags?
    Thanks,
    Zubair.

    Zubair- you should distribute points to the fellow OTNers who helped to answer your question (mark their answers as correct or helpful - just a forum etiquette)

  • How can I create a array with all files from a directory

    How can I create a array of files or varchar with all files from a directory?

    I thought the example could be improved upon. I've posted a solution on my blog that doesn't require writing the directory list to a table. It simply returns it as a nested table of files as a SQL datatype. You can find it here:
    http://maclochlainn.wordpress.com/2008/06/05/how-you-can-read-an-external-directory-list-from-sql/

  • How to fill array with random number?

    I need to fill a 3-dimensional array that has user-controlled dimension sizes with random numbers (1-10). I'm unsure of how to do this. I feel like I have to use the initialize array and maybe the build array functions somehow but I'm not entirely sure. Any help would be appreciated. Thanks.

    Something like this
    Kudos are always welcome if you got solution to some extent.
    I need my difficulties because they are necessary to enjoy my success.
    --Ranjeet
    Attachments:
    Array with random number.vi ‏9 KB

  • Fill array with Hue values

    Trying to build (simple) color palette, but keep getting ArrayIndexOutOfBoundsException: 0 when trying to fill the array with Hue values (Saturation and Brightness remain 100%):
    private Color[] hsb = new Color[numberOfCircles];
    float h=0;
    float raise=(1.f/numberOfCircles);
    for (int i=0; i<stKrogcev; i++) {
        hsb=Color.getHSBColor(h,1.0f,1.0f); //getHSBColor: "Creates a Color object based on the specified values for the HSB color model."
    h+=raise;
    }What am I doing wrong?
    What other way could you fill array (Color, int, float, ...) with Hue values?
    This is what I have thus far (only colors missing; not sure whether Sun supports images):  [http://www.shrani.si/f/1G/uM/v29MKIC/palette.jpg]. First three columns in the right-hand table are awaiting RGB values respectively, the last column gets Hue value.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    pbrockway2, numberOfCircles (or stKrogcev ) is an int, and is NOT zero. That Color[] hsb is zero.
    import javax.swing.*;
    import java.awt.*;
    public class BarvnaPaleta {
         public static void main (String[] args) {
              System.out.print("Stevilo krogcev: ");
              int n = BranjePodatkov.preberiInt(); // BranjePodatkov: just some custom class for reading input
              Okno o = new Okno(n);
              o.setVisible(true);
    class Okno extends JFrame {
         RisalnaPlosca risalna;
         public Okno(int n) {
              setTitle("Barvna Paleta");
              setSize(1200,900);
              setLocation(0,0);
              setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              risalna = new RisalnaPlosca(n);
              add(risalna);
    class RisalnaPlosca extends JPanel {
         private final int ROB = 300;     
         int     stKrogcev;
         private int izhX, izhY;     
         private int     r1;
         private int     sirina = 60;     
         private int     visina = 20;     
         private double x, y, r2, r3;     
         private double vmesniKot;
         private double polovicaVmesnegaKota;
         //the much needed color arrays
         public Color[] hsb = new Color[stKrogcev];     
         private String[] red = new String[stKrogcev];     
         private String[] green = new String[stKrogcev];     
         private String[] blue = new String[stKrogcev];     
         public RisalnaPlosca(int n) { //constructor     
              stKrogcev = n;
              setBackground(Color.white);
         public void paintComponent(Graphics g) {
              super.paintComponent(g);
              izhX = getWidth()/2 -r1;
              izhY = getHeight()/2 -r1;          
              vmesniKot=(2*Math.PI/stKrogcev);
              polovicaVmesnegaKota=(vmesniKot)/2;          
              r1=getHeight();
              r3=(r1*Math.sin(polovicaVmesnegaKota))/(1+Math.sin(polovicaVmesnegaKota));
              r2=r1-r3;                    
              narisiKrog(g);
              napolniHSB(g); //  LINE 53
              narisiKrogce(g);
         private void narisiKrog(Graphics g) { //draw the BIG Circle
              g.setColor(Color.BLACK);
              g.drawOval(0, 0, r1, r1);
         private void narisiKrogce(Graphics g) { //draw small circles (as many as user wants, max. is 256 of Hue values!
              for(int i=0; i<stKrogcev; i++) {
                   x=(r2/2)*(Math.cos(vmesniKot*i)+1);
                   y=(r2/2)*(Math.sin(vmesniKot*i)+1);
                           //can't use below two because of the "fillHSB"=="napolniHSB" method not working
                   //Color c = new Color(Integer.parseInt(red),Integer.parseInt(green[i]),Integer.parseInt(blue[i]));
                   //g.setColor(c);
                   g.drawOval((int)x, (int)y, (int)r3, (int)r3);
                   narisiLegendo((int)x,(int)y, i, g); //draw a legend (last method)
         private void napolniHSB(Graphics g) { //fillHSB method
    float h=0, raise=1.0f/stKrogcev;
    for (int i=0; i<stKrogcev; i++) {
    hsb[i]=Color.getHSBColor(h,1.0f,1.0f); // LINE 75
    red[i]=Integer.toString(hsb[i].getRed()); // this and below two for converting HSB/HSL into RGB
    green[i]=Integer.toString(hsb[i].getGreen());
    blue[i]=Integer.toString(hsb[i].getBlue());
    h+=raise;
         private void narisiLegendo(int x, int y, int i, Graphics g) { //draw a legend, i.e. 4 right columns
    //can't use drawString as there are no color arrays (yet)
                   g.drawLine((int)(x+r3/2),(int)(y+r3/2),getWidth()-ROB,(visina+i*visina)+visina/2);
                   g.drawRect(getWidth()-ROB, (visina+i*visina), sirina, visina); //Red
                   //g.drawString(red[i], getWidth()-ROB, (visina+i*visina));
                   g.drawRect(getWidth()-ROB+sirina, (visina+i*visina), sirina, visina); //Green
                   //g.drawString(green[i], getWidth()-ROB, (visina+i*visina));
                   g.drawRect(getWidth()-ROB+2*sirina, (visina+i*visina), sirina, visina); //Blue
                   //g.drawString(blue[i], getWidth()-ROB, (visina+i*visina));
                   g.drawRect(getWidth()-ROB+3*sirina, (visina+i*visina), sirina, visina); //Hue
                   //g.drawString(, getWidth()-ROB, (visina+i*visina));

  • Help with oracle sql to get all possible combinations in a table.

    Hello guys I have a small predicatement that has me a bit stumped. I have a table like the following.(This is a sample of my real table. I use this to explain since the original table has sensitive data.)
    CREATE TABLE TEST01(
    TUID VARCHAR2(50),
    FUND VARCHAR2(50),
    ORG  VARCHAR2(50));
    Insert into TEST01 (TUID,FUND,ORG) values ('9102416AB','1XXXXX','6XXXXX');
    Insert into TEST01 (TUID,FUND,ORG) values ('9102416CC','100000','67130');
    Insert into TEST01 (TUID,FUND,ORG) values ('955542224','1500XX','67150');
    Insert into TEST01 (TUID,FUND,ORG) values ('915522211','1000XX','67XXX');
    Insert into TEST01 (TUID,FUND,ORG) values ('566653456','xxxxxx','xxxxx');
    "TUID"                        "FUND"                        "ORG"                        
    "9102416AB"                   "1XXXXX"                      "6XXXXX"                     
    "9102416CC"                   "100000"                      "67130"                      
    "955542224"                   "1500XX"                      "67150"                      
    "915522211"                   "1000XX"                      "67XXX"                      
    "566653456"                   "xxxxxx"                      "xxxxx"                       The "X"'s are wild card elements*( I inherit this and i cannot change the table format)* i would like to make a query like the following
    select tuid from test01 where fund= '100000' and org= '67130'however what i really like to do is retrieve any records that have have those segements in them including 'X's
    in other words the expected output here would be
    "TUID"                        "FUND"                        "ORG"                        
    "9102416AB"                   "1XXXXX"                      "6XXXXX"                     
    "9102416CC"                   "100000"                      "67130"                      
    "915522211"                   "1000XX"                      "67XXX"                      
    "566653456"                   "xxxxxx"                      "xxxxx"  i have started to write a massive sql statement that would have like 12 like statement in it since i would have to compare the org and fund every possible way.
    This is where im headed. but im wondering if there is a better way.
    select * from test02
    where fund = '100000' and org = '67130'
    or fund like '1%' and org like '6%'
    or fund like '1%' and org like '67%'
    or fund like '1%' and org like '671%'
    or fund like '1%' and org like '6713%'
    or fund like '1%' and org like '67130'
    or fund like '10%' and org like '6%'...etc
    /*seems like there should be a better way..*/can anyone give me a hand coming up with this sql statement...

    mlov83 wrote:
    if i run this
    select tuid,fund, org
    from   test01
    where '100000' like translate(fund, 'xX','%%') and '67130' like translate(org, 'xX','%%');this is what i get
    "TUID"                        "FUND"                        "ORG"                        
    "9102416AB"                   "1XXXXX"                      "6XXXXX"                     
    "9102416CC"                   "100000"                      "67130"                      
    "915522211"                   "1000XX"                      "67XXX"                      
    "566653456"                   "xxxxxx"                      "xxxxx"                      
    "9148859fff"                  "1XXXXXX"                     "X6XXX"                       the last item should be excluded. The second digit in "org" is a "7" Fund is wrong, too. You're looking for 6 characters ('100000'), but fund on that row is 7 characters ('1XXXXXX').
    and this is sitll getting picked up.That's why you should use the _ wild-card, instead of %
    select  tuid, fund, org
    from    test01
    where  '100000' like translate (fund, 'xX', '__')
    and    '67130'  like translate (org,  'xX', '__')
    ;It's hard to see, but, in both calls to TRANSLATE, the 3rd argument is a string of 2 '_'s.

  • Fill array with file names

    What am I missing?  I've got alerts that should pop up if it works and if it fails but instead it does nothing, I'm sure its possible to create an array that is made up of all the file names of a folder.  In the past I've had to enter all the values one a time and some of these folders have 200+ files in it.
    #target illustrator
    filltotesTempArr
    function filltotesTempArr()
    var toteTemparray = new Array(toteTemps)
    var toteTempPath = Folder ("S:/Illustrator JS Palette/Direct Template Calls/Totes");
    var allFiles = artPath.getFiles(order);
    var toteTemps
    if (allFiles.length > 0)
        for (i=0;i<allFiles.length;i++)
                toteTemps = toteTemps + app.open(allFiles[i] )
              }//end for
          alert("Your array has the current values:" + toteTemps);
        }//end if
        else
        alert("Script to fill Totes Templates Array has failed");

    I need to take all the files inside of a folder, and put their file names in an array like this;
    var totesarr1= new Array ("A165331","A165332","A165333","A165334","A165337","A165338","A165344","A165348", "A165349",
    "A165352","A165353","A203","A210","A211","A214","A222","A229","A231","A232","A234","A248","A250","A252","A268",
    "A271","A272","A278","A290","A292","A322","A323","A324","A325","A327","A330","A402","A404","A405","A407","A408",
    "A409","A410","A411","A414","A415","A417","A420","A422","A423","A424","A425","A427","A430","A436","A438","A439",
    "A440","A441","A443","A446","A448","A449","A450","A451","A452","A454","A455","A456","A460","A461","A468","A470",
    "A490","A495","A497","A500","A508","A509","A510","A512","A513","A514","A518","A524","A525","A526","A527","A530",
    "A533","A534","A536","A543","A581","A582","A587","A602","A619","A624","A705","A707","A710","A714","A715","A739",
    "A740","A741","A742","A743","A744","A745","A748","A750","A751","A752","A753","A754","A755","A756","A763","A800",
    "A801","A804","A806","A811","A815","A817","A818","A819","A824","A832","A835","A836","A838","A841","A844","A848",
    "A849","A852","A854","A856","A857","A859","A861","A863","A865","A866","A868","A871","A873","A877","A879","A881",
    "A885","A888","A890","A894","A899","A900","A902","A904","A940","A941","A943","A944","A945","A948","A97307","A97309",
    "A97313","A97314","A97315","A97316","A97321","A97326","A97340","A97342","A97708","A97715","F742","F751","V6432");
    so the closest thing that I can come up with is this;
    #target illustrator
    filltotesTempArr
    function filltotesTempArr()
    var toteTemparray = new Array(toteTemps)
    var order = new RegExp(input);
    var toteTempPath = Folder ("S:/Illustrator JS Palette/Direct Template Calls/Totes");
    var totetempnames = toteTempPath.getFiles();
    var totetemps = new Array ()
    var allFiles = toteTempPath.getFiles();
    if (allFiles.length > 0)
        for (i=0;i<allFiles.length;i++)
                toteTemps = toteTemps + "," + app.open(allFiles[i])
              }//end for
          alert("Your array has the current values:" + toteTemps);
        }//end if
        else
        alert("Script to fill Totes Templates Array has failed");
    alert ("Script is Done")
    but even this dosn't work like it should
    #target Illustrator
    GetTempNames;
    function GetTempNames ()
    var toteTempPath = Folder ("S:/Illustrator JS Palette/Direct Template Calls/Totes");
    var toteTempNames = toteTempPath.getFiles()
    var totetemparr = new Array ( toteTempNames )
    alert ("script is done get ready");
        alert ("Here " + totetemparr);
    so now I'm at a loss

  • Spline Engine returns zero with all possible inputs

    Hello,
    The Spline Engine in my FPGA code for my controller appears to not be working under any inputs. I have set both reset position and spline data updated to TRUE and made the spline data output equivalent to the highest possible number. The documentation for the spline engine says that with reset position set to zero then the output is set to coefficient 0. This doesn't occur either. I think it is caused by the fact that output valid is always FALSE even though my inputs should provoke a response. Attached is the related segments of my front panel and block diagram.
    Running on a cRIO 9022.
    Any help would be appreciated,
    rustawilliams
    Attachments:
    Problem with Spline Engine.png ‏70 KB

    If you look at the documentation for the spline engine, http://zone.ni.com/reference/en-XX/help/371093G-01/nismlvhlp/spline_engine/ , reset position TRUE is supposed to set setpoint to coefficient 0 which is not happening. When reset position is FALSE the output valid Boolean indicator is still FALSE and setpoint is still 0.

  • Multiple Choice Quiz with all possible answers weighted

    I am currently trying to create a multiple choice quiz with 29 questions nin captivate 5.5. Every question will have 4 answers similar to those on a standard survey (Strongly agree, Agree, Disagree, Strongly Diagree.) Dependent on the answer given I would like each answer to have a weighted value between 1-4  to give a final score which will be sectioned into 3 categories. I am able to weight a question but can't figure out how I can weight all answers per question. Any help would be grealy appreciated

    Hello and welcome to the forum
    You created custom question slides, I suppose? How familiar are you with advanced actions and variables? I published some articles and blog a lot about them. Here you'll find a list with articles, think that the first 1 of them could give you an idea how to proceed. Can you read them, and later I will try to help you if you are stuck. Will need some more details in that case about 'how I can weight all answers per question.' Moreover, do you want to report to a LMS or is the conclusion about the final score to provide feedback to the user?
    Lilybiri

  • How can I multiply all values of a 4-element array with all of its inverse values resulting to an array having all 16 products?

    I'm quite new to LabVIEW (v.8.0) and I'm trying to figure out the easiest way to have a 4-element array multiplied by its inverse values resulting in a 16-element array
    Array 1 values = 1, 2, 3, 4
    Array 1 inverse values = 1, 0.5, 0.33, 0.25
    Resulting array = (1, 0.5, 0.33, 0.25, 2, 1, 0.66, 0.5, 3, 1.5, 1, 0.75, 4, 2, 1.32, 1)
    Any advice would be appreciated. Thanks!
    Solved!
    Go to Solution.

    Attachments:
    mo.doc ‏27 KB

Maybe you are looking for