-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) | ||
} | ||
} |