Skip to content

Commit

Permalink
Run formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
jsoberg committed Dec 8, 2024
1 parent 2d4f17b commit e5d3fe7
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -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<T>(
private val grid: List<List<T>>,
Expand Down Expand Up @@ -58,7 +56,7 @@ data class Grid2D<T>(
from: Location,
direction: Direction,
numElementsToCollect: Int,
) : List<T>? {
): List<T>? {
val finalLocation = from.move(direction, numElementsToCollect - 1)
if (!isInBounds(finalLocation)) {
return null
Expand All @@ -72,7 +70,7 @@ data class Grid2D<T>(

/** @return Map of elements to list of their respective locations. */
fun elementToLocationsMap(): Map<T, List<Location>> =
filterElementToLocationsMap(filter = { _,_ -> true })
filterElementToLocationsMap(filter = { _, _ -> true })

/** @return Map of elements and their respective locations in the grid that pass [filter]. */
fun filterElementToLocationsMap(
Expand Down Expand Up @@ -190,7 +188,7 @@ data class Grid2D<T>(
)

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)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -36,7 +40,7 @@ suspend inline fun <T> Iterable<T>.asyncSumOf(crossinline selector: (T) -> Int):
inline fun <T> Iterable<T>.asyncSumOfBlocking(
dispatcher: CoroutineDispatcher = Dispatchers.Default,
crossinline selector: (T) -> Long,
): Long = runBlocking(dispatcher){
): Long = runBlocking(dispatcher) {
asyncSumOf(selector)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand All @@ -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)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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()
}
Expand Down

0 comments on commit e5d3fe7

Please sign in to comment.