I want to find cartesian product of set of elements. Here's an example
example 1:
sets : (ab) (bc) (ca)
cartesian product is:
abc aba acc aca bbc bba bcc bca
example 2:
sets : (zyx) b c
cartesian product is:
zbc ybc xbc
So I am thinking of an algorithm to execute in Java which can find cartesian product of particular amount of groups defined at compile time at the start.
You can use the Sets.cartesianProduct()
method from Google's Guava libraries to generate Cartesian products:
com.google.common.collect.Sets.cartesianProduct(Set[] yourSets)
If only everything was that easy!
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