aboutsummaryrefslogtreecommitdiff
path: root/src/Utils.kt
diff options
context:
space:
mode:
authortchojnacki <tomaszchojnacki2001@gmail.com>2021-12-14 12:57:10 +0100
committertchojnacki <tomaszchojnacki2001@gmail.com>2021-12-14 12:57:10 +0100
commitfbd07e79691c848582b792da46f0deb52957b686 (patch)
treeb7d8e0724144a6f453b915583bee51ca2e712f68 /src/Utils.kt
parentd0690ab93cb82efe575d77d117426ab2d5eafaa9 (diff)
downloadgleam_aoc2020-fbd07e79691c848582b792da46f0deb52957b686.tar.gz
gleam_aoc2020-fbd07e79691c848582b792da46f0deb52957b686.zip
Finish day 11
Diffstat (limited to 'src/Utils.kt')
-rw-r--r--src/Utils.kt15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/Utils.kt b/src/Utils.kt
index 492c71d..c0f4f61 100644
--- a/src/Utils.kt
+++ b/src/Utils.kt
@@ -34,12 +34,25 @@ fun readInputAsBitLists(name: String): List<List<Int>> =
data class Pos2D(val x: Int, val y: Int) {
companion object {
- val directions = listOf(Pos2D(0, 1), Pos2D(1, 0), Pos2D(0, -1), Pos2D(-1, 0))
+ val directions4 = listOf(Pos2D(0, 1), Pos2D(1, 0), Pos2D(0, -1), Pos2D(-1, 0))
+ val directions8 = directions4 + listOf(
+ Pos2D(1, 1),
+ Pos2D(1, -1),
+ Pos2D(-1, -1),
+ Pos2D(-1, 1),
+ )
}
operator fun plus(other: Pos2D) = Pos2D(x + other.x, y + other.y)
}
+fun parseToMap(input: List<String>): Map<Pos2D, Int> =
+ input.flatMapIndexed { y, line ->
+ line.mapIndexed { x, char ->
+ Pos2D(x, y) to char.toString().toInt()
+ }
+ }.toMap()
+
/**
* Converts string to md5 hash.
* @receiver a string