Dmitry Nekrasov
11/06/2025, 12:05 PMzsmb
11/06/2025, 12:12 PMphldavies
11/06/2025, 1:08 PMephemient
11/06/2025, 4:26 PMJakub Gwóźdź
11/07/2025, 6:27 AMephemient
11/07/2025, 6:49 AMephemient
11/07/2025, 6:56 AMJakub Gwóźdź
11/07/2025, 7:08 AMCaroline Mouden
11/07/2025, 10:05 AMDmitry Nekrasov
11/07/2025, 10:34 AMJakub Gwóźdź
11/07/2025, 10:49 AMdata class Pos(...) every one year...Jakub Gwóźdź
11/07/2025, 10:57 AMtypealias Pos = Long with companion functions that treats one half of bits as row and another as column - should be a benchmark killer)ephemient
11/07/2025, 11:39 AM@JvmInline
value class IntPair private constructor(private val packed: Long) {
constructor(first: Into, second: Int) : this(first.toLong().shl(32) or second.toLong().and(0xffffffffL))
val first: Int
get() = packed.shr(32).toInt()
val second: Int
get() = packed.toInt()
}
plus copy and operator component# if you wantDmitry Nekrasov
11/07/2025, 11:41 AMJakub Gwóźdź
11/07/2025, 11:57 AMNorbert Kiesel
11/08/2025, 12:22 AMString.ints() which extracts all Ints from a string (which is often required to parse the puzzle inputs).ephemient
11/08/2025, 1:46 AM./gradlew --continuous jvmTest running in the background to immediately see results as I codeJakub Gwóźdź
11/08/2025, 1:57 PMfun main() { ... } in every day's file, but then I also have this gem in my `Commons.kt`:
inline fun go(expected: Any? = null, desc: String = "", op: () -> Any) {
val result = op()
println("$desc$result")
if (expected != null) check(result.toString() == expected.toString()) { "expected $expected" }
}
and my main() calls it with expected results (for examples) like:
fun main() {
go(4, "Example 1a:") { part1(example1) }
go(2024, "Example 1b:") { part1(example2) }
go(45213383376616) { part1(readAllText("local/day24_input.txt")) }
go() { part2(readAllText("local/day24_input.txt")) }
...
}Jakub Gwóźdź
11/08/2025, 1:59 PMDmitry Nekrasov
11/11/2025, 4:17 PMJakub Gwóźdź
11/11/2025, 4:35 PMNorbert Kiesel
11/13/2025, 1:09 AMDan Fingal-Surma
11/26/2025, 6:57 AM.main.kts file that can be directly executed on the command line. Dijkstra’s algo usually gets reimplemented a few times, though usually a little differently such that extracting out a command method hasn’t been worthwhile. Also repeated data class Point and enum class Direction, but they also often have variations. From the JDK I just use java.io.File and java.util.PriorityQueue. I did have to use kotlinx.serialization.json for one old 2015 problem I did. All the kotlin.collections methods are the real MVPs for me.Jakub Gwóźdź
11/26/2025, 7:24 AMDmitry Nekrasov
11/26/2025, 7:42 AMDerek Peirce
12/19/2025, 7:09 AM(i, j) to neighboring points on an m x n grid:
for (nextI in (i - 1).coerceAtLeast(0)..(i + 1).coerceAtMost(m - 1) {
for (nextJ in (j - 1).coerceAtLeast(0)..(j + 1).coerceAtMost(n - 1) {
if ((i == nextI) != (j == nextJ)) { // if diagonals are not allowed
...
}
}
}
A simpler forEachNeighbor(i, j, m, n) { nextI, nextJ -> ... } call would help.
I also often use, for example, Array(m) { IntArray(n) }, but sometimes use IntArray(m * n) with a lookup of array[i * n + j]. and decomposition of i = pos / n and j = pos % n. Any way to more clearly express a linear array as simulating a grid would be much appreciated.
Finally, more of a language request than a library request, I very often write `when`s where the else is an error, and end up with things like:
when (parsedString[i++]) {
'(' -> ...
')' -> ...
else -> throw IllegalStateException()
}
and it would be very nice if a shortcut like else throw or else -> throw would automatically add the when (val case = ...) and generate a nice throw IllegalStateException("Invalid case $case") for error checking.