diff options
author | tchojnacki <tomaszchojnacki2001@gmail.com> | 2022-08-13 12:25:41 +0200 |
---|---|---|
committer | tchojnacki <tomaszchojnacki2001@gmail.com> | 2022-08-13 12:25:41 +0200 |
commit | 992d24939100a6adb466b23449a62c36736b4249 (patch) | |
tree | 778ff441bb0a14ac64aca2d6dde67b4133e566a0 /aoc-2021-kotlin/src/Utils.kt | |
parent | 2ef3cacc7766c55f3e40803e37864acc4bd4c918 (diff) | |
download | gleam_aoc2020-992d24939100a6adb466b23449a62c36736b4249.tar.gz gleam_aoc2020-992d24939100a6adb466b23449a62c36736b4249.zip |
Finish day 20
Diffstat (limited to 'aoc-2021-kotlin/src/Utils.kt')
-rw-r--r-- | aoc-2021-kotlin/src/Utils.kt | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/aoc-2021-kotlin/src/Utils.kt b/aoc-2021-kotlin/src/Utils.kt index 8fe3f75..4f78a1f 100644 --- a/aoc-2021-kotlin/src/Utils.kt +++ b/aoc-2021-kotlin/src/Utils.kt @@ -22,6 +22,8 @@ data class Pos2D(val x: Int, val y: Int) { } operator fun plus(other: Pos2D) = Pos2D(x + other.x, y + other.y) + + operator fun minus(other: Pos2D) = Pos2D(x - other.x, y - other.y) } fun parseToMap(input: List<String>): Map<Pos2D, Int> = @@ -30,3 +32,12 @@ fun parseToMap(input: List<String>): Map<Pos2D, Int> = Pos2D(x, y) to char.toString().toInt() } }.toMap() + +fun <T> combinations(first: Iterable<T>, second: Iterable<T> = first): Sequence<Pair<T, T>> = + sequence { + first.forEach { a -> + second.forEach { b -> + yield(a to b) + } + } + } |