This is my first post in here. Today I started using combinatoric library for Java.
This one: https://github.com/dpaukov/combinatoricslib3
I've got more than 10k length of sides of triangle in Excel. Than i pulled them into 2d Integer array.
Than i created class Triangle:
public class Triangle {
private int a;
private int b;
private int c;
public Triangle(int a, int b, int c)
{
this.a = a;
this.b = b;
this.c = c;
}
public boolean isCorrect()
{
if(this.a + this.b > this.c)
return true;
return false;
}
}
My problem is that I can generate all possible combinations of Triangles but have no idea how to created object Triangle. Only know how to print result.
public static void main(String[] args) throws IOException {
Generator.combination(sides).simple(3).stream().forEach(System.out::println);
}
Thank you in advance. Cheers!
EDIT:
This is example of sides:
static final int[][] sides = new int[][]{
{71, 100, 1231, 832, 127},
{336, 447, 815, 658, 373},
{126, 444, 556, 221, 1322},
{1226, 662, 985, 87, 991},
{555, 512, 111, 339, 22},
};
I want to generate all possible Triangles with this data.
Should look something like that:
Generator
.combination(sides)
.simple(3)
.stream()
.forEach(
sides -> new Triangle(sides[0],sides[1],sides[2])
);
Note that this implies that the sides are integer, if not (e.g. strings) you might need to additionally convert (map) them to a proper type.
Now, if you want for example to collect them all to list, you can do:
List<Triangle> triangles = Generator
.combination(sides)
.simple(3)
.stream()
.map(sides -> new Triangle(sides[0],sides[1],sides[2]))
.collect(Collectors.toList())
You can iterate over a two-dimensional int[][] array, and find all the combinations for each line, like that:
Arrays.stream(sides)
.forEach(
line -> {
Generator.combination(Arrays.stream(line).boxed().collect(Collectors.toList()))
.simple(3)
.stream()
.forEach(System.out::println);
}
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With