Friday, 10 June 2016

cartesian , inter cross combinations

String varients[][]={
        {"A","B","C"},
        {"S","U","N"},
        {"R","G","B"},
        {"30","35","37"}
};

int totCombination=1;

for(int i = 0; i < varients.length; i++)
{
    totCombination=totCombination * varients[i].length;
}

try {

    String outStr = "";

    for (int cat = 0; cat < totCombination; cat++) {
        int looptotal = totCombination;

        outStr=outStr+cat+"===>";

        for (int item = 0; item < varients.length; item++) {
            int part = looptotal / varients[item].length;

            looptotal = part;//totCombination/part
            int selItem = (cat / (looptotal))%varients[item].length;

            outStr = outStr + (item==0?"":",")+ varients[item][selItem];
        }
        outStr = outStr + "\n";
    }

    Log.i("Item", "" + outStr);


}catch (Exception ex)
{
    Log.i("Item", "" + ex.toString());
}