math - Finding cartesian product in Java -
i want find cartesian product of set of elements. here's 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 thinking of algorithm execute in java can find cartesian product of particular amount of groups defined @ compile time @ start.
you can use sets.cartesianproduct()
method google's guava libraries generate cartesian products:
com.google.common.collect.sets.cartesianproduct(set[] yoursets)
if easy!
Comments
Post a Comment