File tree Expand file tree Collapse file tree 2 files changed +13
-1
lines changed
main/kotlin/de/ronny_h/aoc/extensions
test/kotlin/de/ronny_h/aoc/extensions Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ import java.lang.Math.pow
66/* *
77 * @return All pairwise combinations of list elements without the reflexive ones.
88 */
9- fun <E > List <E>.combinations () = sequence {
9+ fun <E > Iterable <E>.combinations () = sequence {
1010 forEachIndexed { i, a ->
1111 forEachIndexed { j, b ->
1212 if (i != j) {
Original file line number Diff line number Diff line change @@ -32,6 +32,18 @@ class CombinationsTest : StringSpec({
3232 )
3333 }
3434
35+ " a range with three elements yields all six combinations" {
36+ (1..3).combinations().toList() shouldBe
37+ listOf(
38+ 1 to 2,
39+ 1 to 3,
40+ 2 to 1,
41+ 2 to 3,
42+ 3 to 1,
43+ 3 to 2
44+ )
45+ }
46+
3547 " a list with non-unique elements yields non-unique combinations but still skips the identical ones" {
3648 listOf(1, 1, 2).combinations().toList() shouldBe
3749 listOf(
You can’t perform that action at this time.
0 commit comments