diff options
author | tchojnacki <tomaszchojnacki2001@gmail.com> | 2022-08-11 19:24:23 +0200 |
---|---|---|
committer | tchojnacki <tomaszchojnacki2001@gmail.com> | 2022-08-11 19:24:23 +0200 |
commit | 0f1e145b80813ae2331b7dac5ace0c589654ad2a (patch) | |
tree | 25483b8239436dd5aed2fee8811caf0ba893c0bb /2021-kotlin/src/Utils.kt | |
parent | 85fb0396bed6a2129b12392941103924b1ab55be (diff) | |
download | gleam_aoc2020-0f1e145b80813ae2331b7dac5ace0c589654ad2a.tar.gz gleam_aoc2020-0f1e145b80813ae2331b7dac5ace0c589654ad2a.zip |
Move subproject to avoid IntelliJ module name issues
Diffstat (limited to '2021-kotlin/src/Utils.kt')
-rw-r--r-- | 2021-kotlin/src/Utils.kt | 32 |
1 files changed, 0 insertions, 32 deletions
diff --git a/2021-kotlin/src/Utils.kt b/2021-kotlin/src/Utils.kt deleted file mode 100644 index f0a420b..0000000 --- a/2021-kotlin/src/Utils.kt +++ /dev/null @@ -1,32 +0,0 @@ -import java.io.File - -fun readInputAsLines(name: String): List<String> = File("src", "$name.txt").readLines() - -fun readInputAsString(name: String): String = File("src", "$name.txt").readText() - -fun readInputAsNumbers(name: String): List<Int> = readInputAsLines(name).map(String::toInt) - -fun readInputAsBitLists(name: String): List<List<Int>> = - readInputAsLines(name) - .map { binaryString -> binaryString.toList().map { bit -> bit.toString().toInt() } } - -data class Pos2D(val x: Int, val y: Int) { - companion object { - 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() |