File tree Expand file tree Collapse file tree 6 files changed +47
-9
lines changed
Expand file tree Collapse file tree 6 files changed +47
-9
lines changed Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ internal class Binary(
1818 bits[index]
1919
2020 operator fun not () =
21- Binary (bits.map { ! it }.toTypedArray() )
21+ Binary (bits.mapToArray { ! it })
2222
2323 override fun iterator () =
2424 bits.iterator()
@@ -28,7 +28,7 @@ internal fun Collection<Bit>.toBinary() =
2828 Binary (toTypedArray())
2929
3030internal fun String.toBinary () =
31- Binary (map { it.toBit() }.toTypedArray() )
31+ Binary (mapToArray { it.toBit() })
3232
3333internal fun Path.readBinaries () =
3434 readLines().map { it.toBinary() }
Original file line number Diff line number Diff line change 1+ class Day00 : Day {
2+ override fun partOne (filename : String , verbose : Boolean ): Any {
3+ TODO (" Not yet implemented" )
4+ }
5+
6+ override fun partTwo (filename : String , verbose : Boolean ): Any {
7+ TODO (" Not yet implemented" )
8+ }
9+
10+ companion object : Day .Main (" Day00.txt" ) {
11+ @JvmStatic
12+ fun main (args : Array <String >) = main()
13+ }
14+ }
Original file line number Diff line number Diff line change @@ -26,14 +26,10 @@ val <T> Matrix<T>.width
2626 * Interpret [this] as a filename and parse its contents to a matrix
2727 */
2828internal inline fun <reified T > Path.parseMatrix (charTransformer : (Char ) -> T ): Matrix <T > =
29- readLines()
30- .map { it.map(charTransformer).toTypedArray() }
31- .toTypedArray()
29+ readLines().mapToArray { it.mapToArray(charTransformer) }
3230
3331internal inline fun <reified T > String.parseMatrix (charTransformer : (Char ) -> T ): Matrix <T > =
34- lines()
35- .map { it.map(charTransformer).toTypedArray() }
36- .toTypedArray()
32+ lines().mapToArray { it.mapToArray(charTransformer) }
3733
3834fun Path.parseMatrix () =
3935 parseMatrix { it }
Original file line number Diff line number Diff line change @@ -43,6 +43,15 @@ fun <T> Set<T>.filter(predicate: (T) -> Boolean): Set<T> =
4343fun <K , V > Iterable <Pair <K , V >>.toMutableMap () =
4444 toMap(mutableMapOf ())
4545
46+ inline fun <T , reified R > List<T>.mapToArray (transform : (T ) -> R ) =
47+ Array (size) { transform(get(it)) }
48+
49+ inline fun <reified R > CharSequence.mapToArray (transform : (Char ) -> R ) =
50+ Array (length) { transform(get(it)) }
51+
52+ inline fun <T , reified R > Array<T>.mapToArray (transform : (T ) -> R ) =
53+ Array (size) { transform(get(it)) }
54+
4655fun <T > List<T>.allPairs (): List <Pair <T , T >> =
4756 dropLast(1 ).flatMapIndexed { index, element -> drop(index + 1 ).map { element to it } }
4857
Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ fun <T> calculateShortestPathFromSource(source: Node<T>) {
55 val settledNodes = mutableSetOf<Node <T >>()
66 val unsettledNodes = mutableSetOf (source)
77
8- while (unsettledNodes.size != 0 ) {
8+ while (unsettledNodes.isNotEmpty() ) {
99 val currentNode = getLowestDistanceNode(unsettledNodes)
1010 unsettledNodes - = currentNode
1111 for ((adjacentNode, edgeWeigh) in currentNode.adjacentNodes) {
Original file line number Diff line number Diff line change 1+ import org.junit.jupiter.api.assertThrows
2+ import kotlin.test.Test
3+
4+ class Day00Test : DayTest <Day00 >() {
5+
6+ @Test
7+ override fun `Part One` () {
8+ assertThrows<NotImplementedError > {
9+ target.partOne(" " , true )
10+ }
11+ }
12+
13+ @Test
14+ override fun `Part Two` () {
15+ assertThrows<NotImplementedError > {
16+ target.partTwo(" " , true )
17+ }
18+ }
19+ }
You can’t perform that action at this time.
0 commit comments