So I have an array of doubles. I want to find a subset within this array of size k, and store all those not in the subset into a different subarray. I want to do this for all possible subsets, without repetition.
What is the best approach?
double[] sample = {
1.0, 3.0, 1.6, 2.1, 2.5, 2.7, 2.3, 1.5, 1.1, 0.5, 2.0, 2.0, 1.2, 1.2, 1.3, 0.5, 1.4, 2.4
};
public static void main(String[] args) {
ArrayList < double[] > list = new ArrayList < double[] > ();
double[] noo = pickNRandom(sample);
if (!list.contains(noob)) { //here I want to make sure that it is a unique subset
list.add(noob);
for (double a: noob) {
System.out.print(a + " ");
}
System.out.println("");
}
}
public static double[] pickNRandom(double[] lst) { //finding a random subset
double[] i = lst;
Collections.shuffle(Arrays.asList(i));
double[] fin = {
i[0], i[1], i[2], i[3], i[4], i[5], i[6], i[7]
};
return fin;
}