From d340ddf064b939a6317f64ea99291580e0670637 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20R=C3=B8dland?= Date: Mon, 16 Dec 2024 07:43:55 +0100 Subject: [PATCH] 2024 - Day 16 - parse --- src/main/kotlin/no/rodland/advent/Cave.kt | 2 ++ src/main/kotlin/no/rodland/advent_2024/Day16.kt | 12 ++++++------ src/test/resources/2024/input_16_test.txt | 15 +++++++++++++++ 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/main/kotlin/no/rodland/advent/Cave.kt b/src/main/kotlin/no/rodland/advent/Cave.kt index 35c0883f..e28d58cc 100644 --- a/src/main/kotlin/no/rodland/advent/Cave.kt +++ b/src/main/kotlin/no/rodland/advent/Cave.kt @@ -29,6 +29,8 @@ fun fromMap(map: Map): Cave { } } +fun List.toCave(): Cave = map { line -> line.toCharArray() }.toTypedArray() + @Suppress("UNUSED_PARAMETER") fun Cave.print(minX: Int = 0, minY: Int = 0, maxX: Int = first().size, maxY: Int = size) { forEach { ca -> diff --git a/src/main/kotlin/no/rodland/advent_2024/Day16.kt b/src/main/kotlin/no/rodland/advent_2024/Day16.kt index c9f41d72..720b2f58 100644 --- a/src/main/kotlin/no/rodland/advent_2024/Day16.kt +++ b/src/main/kotlin/no/rodland/advent_2024/Day16.kt @@ -1,13 +1,15 @@ package no.rodland.advent_2024 +import no.rodland.advent.Cave import no.rodland.advent.Day +import no.rodland.advent.toCave // template generated: 15/12/2024 // Fredrik Rødland 2024 -class Day16(val input: List) : Day> { +class Day16(val input: List) : Day> { - private val parsed = input.parse() + private val maze = input.parse() override fun partOne(): Long { return 2 @@ -17,10 +19,8 @@ class Day16(val input: List) : Day> { return 2 } - override fun List.parse(): List { - return map { line -> - line - } + override fun List.parse(): Cave { + return this.toCave() } override val day = "16".toInt() diff --git a/src/test/resources/2024/input_16_test.txt b/src/test/resources/2024/input_16_test.txt index e69de29b..6a5bb850 100644 --- a/src/test/resources/2024/input_16_test.txt +++ b/src/test/resources/2024/input_16_test.txt @@ -0,0 +1,15 @@ +############### +#.......#....E# +#.#.###.#.###.# +#.....#.#...#.# +#.###.#####.#.# +#.#.#.......#.# +#.#.#####.###.# +#...........#.# +###.#.#####.#.# +#...#.....#.#.# +#.#.#.###.#.#.# +#.....#...#.#.# +#.###.#.#.#.#.# +#S..#.....#...# +############### \ No newline at end of file