package prog8tests.helpers fun cartesianProduct(c1: Collection, c2: Collection): Sequence> { return c1.flatMap { lhsElem -> c2.map { rhsElem -> lhsElem to rhsElem } }.asSequence() } fun cartesianProduct(c1: Collection, c2: Collection, c3: Collection): Sequence> { return sequence { for (a in c1) for (b in c2) for (c in c3) yield(Triple(a, b, c)) } } data class Product(val first: T, val second: U, val third: V, val fourth: W) fun cartesianProduct( c1: Collection, c2: Collection, c3: Collection, c4: Collection ): Sequence> { return sequence { for (a in c1) for (b in c2) for (c in c3) for (d in c4) yield(Product(a, b, c, d)) } }