From 992d24939100a6adb466b23449a62c36736b4249 Mon Sep 17 00:00:00 2001 From: tchojnacki Date: Sat, 13 Aug 2022 12:25:41 +0200 Subject: Finish day 20 --- aoc-2021-kotlin/src/Utils.kt | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'aoc-2021-kotlin/src/Utils.kt') 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): Map = @@ -30,3 +32,12 @@ fun parseToMap(input: List): Map = Pos2D(x, y) to char.toString().toInt() } }.toMap() + +fun combinations(first: Iterable, second: Iterable = first): Sequence> = + sequence { + first.forEach { a -> + second.forEach { b -> + yield(a to b) + } + } + } -- cgit v1.2.3