Skip to content

Commit

Permalink
D18P1
Browse files Browse the repository at this point in the history
  • Loading branch information
hibob224 committed Dec 18, 2024
1 parent 1143b65 commit d61db06
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/main/kotlin/y2024/day18/Day18.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package y2024.day18

import utils.Point
import utils.getInputFile
import utils.shortestPath

fun main() {
println("Part one: " + Day18.solvePartOne())
println("Part two: " + Day18.solvePartTwo())
}

object Day18 {

private val example = false
private val p1GridSize = if (example) 6 else 70
private val p1Bytes = if (example) 12 else 1024

private fun parseInput(bytes: Int) = getInputFile(this::class.java.packageName, example = example)
.readLines()
.take(bytes)
.associate {
val (x, y) = it.split(",").map(String::toInt)
Point(x, y) to '#'
}


fun solvePartOne(): Int {
val grid = parseInput(p1Bytes)

// grid.printGrid()

return grid.shortestPath(
start = Point(0, 0),
target = Point(p1GridSize, p1GridSize),
) { _, new, _ ->
if (new in grid) -1 else 1
}.also {
// println(it.first)
}.second
}

fun solvePartTwo(): Long {
return 0
}
}
25 changes: 25 additions & 0 deletions src/main/kotlin/y2024/day18/example.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
5,4
4,2
4,5
3,0
2,1
6,3
2,4
1,5
0,6
3,3
2,6
5,1
1,2
5,5
2,5
6,5
1,4
0,4
6,4
1,1
6,1
1,0
0,5
1,6
2,0
Binary file added src/main/kotlin/y2024/day18/input.txt
Binary file not shown.
16 changes: 16 additions & 0 deletions src/test/kotlin/y2024/day18/Day18Test.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package y2024.day18

import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test

internal class Day18Test {
@Test
fun solvePartOne() {
assertEquals(334, Day18.solvePartOne())
}

@Test
fun solvePartTwo() {
assertEquals(0, Day18.solvePartTwo())
}
}

0 comments on commit d61db06

Please sign in to comment.