File tree Expand file tree Collapse file tree
src/main/kotlin/adventofcode/common Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -66,10 +66,10 @@ inline fun <reified T : Any?> List<List<T>>.neighbors(
6666 * D E F H E B
6767 * G H I I F C
6868 */
69- inline fun <reified T : Any ? > Collection<Collection<T>>.transpose (): Collection < Collection <T >> {
69+ fun <T > Collection<Collection<T>>.transpose (): List < List <T >> {
7070 val result = first().map { mutableListOf<T >() }
7171 forEach { list -> result.zip(list).forEach { it.first.add(it.second) } }
72- return result.map { it.reversed() }
72+ return result.map( List < T >::reversed)
7373}
7474
7575/* *
Original file line number Diff line number Diff line change 11package adventofcode.common.spatial
22
3+ import adventofcode.common.transpose
4+
35data class Grid2d <T >(
46 val values : List <List <T >>,
57) {
@@ -84,11 +86,7 @@ data class Grid2d<T>(
8486 * [D, E, F] [H, E, B]
8587 * [G, H, I] [I, F, C]
8688 */
87- fun rotateClockwise (): Grid2d <T > {
88- val result = values.first().map { mutableListOf<T >() }
89- values.forEach { list -> result.zip(list).forEach { it.first.add(it.second) } }
90- return Grid2d (result.map(List <T >::reversed))
91- }
89+ fun rotateClockwise (): Grid2d <T > = Grid2d (values.transpose())
9290
9391 /* *
9492 * Returns a new grid by rotating this grid 90deg clockwise.
You can’t perform that action at this time.
0 commit comments