I've been thinking the solution for my project the whole day that needs to permutate n list of objects according to "step" field inside its class. I have the following class:
public class Configuration{
private String name;
private int start; //starting value
private int end; //ending value
private int step; //append this to start value until end value is reached
}
//if I have the following sample:
List<Configuration> configurations = new ArrayList<>();
Configuration config1 = new Configuration("congif1", 1,2,1);
Configuration config2 = new Configuration("config2", 100,200,50);
I need to implement a method:
public Object/void print(List<Configuration> configurations);
Such that the expected output would be (in any order as long as the values are complete)
1,100
2,100
1,150
2,150
1,200
2,200
I need to run through all different configuration scenarios based on user's given configuration setup. If I have 3 objects:
Configuration config1 = new Configuration("congif1", 1,2,1);
Configuration config2 = new Configuration("config2", 100,150,50);
Configuration config3 = new Configuration("config3", 1000,2000,500);
Then the output should be:
1,100,1000
2,100,1000
1,150,1000
2,150,1000
1,100,1500
2,100,1500
1,150,1500
2,150,1500
1,100,2000
2,100,2000
1,150,2000
2,150,2000
I tried the following nested loop but it does not permutate all:
for(Configuration config:configurations){
for(int i=start; i<end; i+=step){
//code here
}
}
I think I need a recursion type for this but I really can't figure out how