diff --git a/src/main/kotlin/com/soberg/aoc/utlities/datastructures/Grid2D.kt b/src/main/kotlin/com/soberg/aoc/utlities/datastructures/Grid2D.kt index 6a5f9b4..20d8113 100644 --- a/src/main/kotlin/com/soberg/aoc/utlities/datastructures/Grid2D.kt +++ b/src/main/kotlin/com/soberg/aoc/utlities/datastructures/Grid2D.kt @@ -1,7 +1,5 @@ package com.soberg.aoc.utlities.datastructures -import kotlin.math.absoluteValue - /** A uniform 2D grid with elements of type [T]. */ data class Grid2D( private val grid: List>, @@ -58,7 +56,7 @@ data class Grid2D( from: Location, direction: Direction, numElementsToCollect: Int, - ) : List? { + ): List? { val finalLocation = from.move(direction, numElementsToCollect - 1) if (!isInBounds(finalLocation)) { return null @@ -72,7 +70,7 @@ data class Grid2D( /** @return Map of elements to list of their respective locations. */ fun elementToLocationsMap(): Map> = - filterElementToLocationsMap(filter = { _,_ -> true }) + filterElementToLocationsMap(filter = { _, _ -> true }) /** @return Map of elements and their respective locations in the grid that pass [filter]. */ fun filterElementToLocationsMap( @@ -190,7 +188,7 @@ data class Grid2D( ) companion object { - infix fun Int.loc(col: Int) : Location = Location(row = this, col = col) + infix fun Int.loc(col: Int): Location = Location(row = this, col = col) } } diff --git a/src/main/kotlin/com/soberg/aoc/utlities/extensions/AsyncSum.kt b/src/main/kotlin/com/soberg/aoc/utlities/extensions/AsyncSum.kt index dce5844..453cbee 100644 --- a/src/main/kotlin/com/soberg/aoc/utlities/extensions/AsyncSum.kt +++ b/src/main/kotlin/com/soberg/aoc/utlities/extensions/AsyncSum.kt @@ -1,6 +1,10 @@ package com.soberg.aoc.utlities.extensions -import kotlinx.coroutines.* +import kotlinx.coroutines.CoroutineDispatcher +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.coroutineScope +import kotlinx.coroutines.launch +import kotlinx.coroutines.runBlocking import java.util.concurrent.atomic.AtomicInteger import java.util.concurrent.atomic.AtomicLong import kotlin.experimental.ExperimentalTypeInference @@ -36,7 +40,7 @@ suspend inline fun Iterable.asyncSumOf(crossinline selector: (T) -> Int): inline fun Iterable.asyncSumOfBlocking( dispatcher: CoroutineDispatcher = Dispatchers.Default, crossinline selector: (T) -> Long, -): Long = runBlocking(dispatcher){ +): Long = runBlocking(dispatcher) { asyncSumOf(selector) } diff --git a/src/test/kotlin/com/soberg/aoc/utlities/datastructures/Grid2DLocationTest.kt b/src/test/kotlin/com/soberg/aoc/utlities/datastructures/Grid2DLocationTest.kt index f495055..a307cf8 100644 --- a/src/test/kotlin/com/soberg/aoc/utlities/datastructures/Grid2DLocationTest.kt +++ b/src/test/kotlin/com/soberg/aoc/utlities/datastructures/Grid2DLocationTest.kt @@ -60,7 +60,7 @@ class Grid2DLocationTest { @JvmStatic fun provideArgumentsForDistanceOfOneMove() = listOf( Arguments.of(Direction.North, Location(9, 10)), - Arguments.of(Direction.NorthEast,Location(9, 11)), + Arguments.of(Direction.NorthEast, Location(9, 11)), Arguments.of(Direction.East, Location(10, 11)), Arguments.of(Direction.SouthEast, Location(11, 11)), Arguments.of(Direction.South, Location(11, 10)), @@ -72,7 +72,7 @@ class Grid2DLocationTest { @JvmStatic fun provideArgumentsForDistanceOfNineMove() = listOf( Arguments.of(Direction.North, Location(1, 10)), - Arguments.of(Direction.NorthEast,Location(1, 19)), + Arguments.of(Direction.NorthEast, Location(1, 19)), Arguments.of(Direction.East, Location(10, 19)), Arguments.of(Direction.SouthEast, Location(19, 19)), Arguments.of(Direction.South, Location(19, 10)), diff --git a/src/test/kotlin/com/soberg/aoc/utlities/datastructures/Grid2DTest.kt b/src/test/kotlin/com/soberg/aoc/utlities/datastructures/Grid2DTest.kt index 23f454e..635171d 100644 --- a/src/test/kotlin/com/soberg/aoc/utlities/datastructures/Grid2DTest.kt +++ b/src/test/kotlin/com/soberg/aoc/utlities/datastructures/Grid2DTest.kt @@ -238,8 +238,8 @@ class Grid2DTest { @Test fun `create expected output string when filtering`() { val grid = listOf( - listOf(1,2,3), - listOf(4,5,6), + listOf(1, 2, 3), + listOf(4, 5, 6), ).toGrid2D() assertThat(grid.toString { "${grid[it] + 1}," }) .isEqualTo( diff --git a/src/test/kotlin/com/soberg/aoc/utlities/extensions/AsyncSumTest.kt b/src/test/kotlin/com/soberg/aoc/utlities/extensions/AsyncSumTest.kt index 2f41ec1..1c4b915 100644 --- a/src/test/kotlin/com/soberg/aoc/utlities/extensions/AsyncSumTest.kt +++ b/src/test/kotlin/com/soberg/aoc/utlities/extensions/AsyncSumTest.kt @@ -16,9 +16,9 @@ class AsyncSumTest { assertThat(letterCount).isEqualTo(36) } - + @Test - fun `return sum of integers - coroutine`() = runTest{ + fun `return sum of integers - coroutine`() = runTest { val letterCount = testData.asyncSumOf { it.length } @@ -36,7 +36,7 @@ class AsyncSumTest { } @Test - fun `return sum of longs - coroutine`() = runTest{ + fun `return sum of longs - coroutine`() = runTest { val letterCount = testData.asyncSumOf { it.length.toLong() }