Skip to content

Commit

Permalink
a little 2019
Browse files Browse the repository at this point in the history
  • Loading branch information
elwaxoro committed Jan 6, 2025
1 parent b7f31ff commit 7d81bfc
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions advent/src/test/kotlin/org/elwaxoro/advent/y2019/Dec19.kt
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class Dec19 : PuzzleDayTester(19, 2019) {
*/
override fun part1(): Any = runBlocking {
TractorBeam(loadToLong(delimiter = ",")).let { t ->
(0..49L).sumOf { y -> (0..49L).count { x -> t.placeDrone(x, y) } }
(0..49).sumOf { y -> (0..49).count { x -> t.placeDrone(x, y) } }
}
} == 131

Expand Down Expand Up @@ -103,14 +103,15 @@ class Dec19 : PuzzleDayTester(19, 2019) {
private class TractorBeam(
val code: List<Long>,
) {
suspend fun placeDrone(x: Int, y: Int): Boolean = placeDrone(x.toLong(), y.toLong())

suspend fun placeDrone(x: Long, y: Long): Boolean {
/**
* returns true if drone is within the tractor beam
*/
suspend fun placeDrone(x: Int, y: Int): Boolean {
val input = mutableListOf(x, y)
var out = -1L
ElfCode(code).runner(
setup = ElfCode.memExpander(5000),
input = { input.removeFirst() },
input = { input.removeFirst().toLong() },
output = { out = it },
)
return out == 1L
Expand Down

0 comments on commit 7d81bfc

Please sign in to comment.