Adam S
12/25/2022, 10:23 AMzokipirlo
12/25/2022, 10:45 AMSergei Petunin
12/25/2022, 12:09 PMwindowed
, aggregations like minOf
/ maxOf
/ minBy
/ maxBy
, functional goodies like fold
and runningFold
, pairs, destructuring, data classes — all this made it a pleasure to solve the puzzles in Kotlin.
As for the missing features, something like Scala's zipAll
would be nice for collections. And for the data classes I missed the possibility to do something like state.copy(clayRobots += 1)
instead of state.copy(clayRobots = clayRobots + 1)
.Sergei Petunin
12/25/2022, 12:21 PMPair.map()
on a couple of occasions...ephemient
12/25/2022, 12:51 PMtranspose
is another missing one IMOephemient
12/25/2022, 12:53 PMOlaf Gottschalk
12/25/2022, 12:56 PMOlaf Gottschalk
12/25/2022, 12:57 PMChisomo Chiweza
12/25/2022, 3:05 PMelizarov
12/25/2022, 3:28 PMChisomo Chiweza
12/25/2022, 4:04 PMephemient
12/25/2022, 4:04 PMclass Tree<T>(var value: T, var left: Tree<T>?, var right: Tree<T>?)
ephemient
12/25/2022, 4:05 PMChisomo Chiweza
12/25/2022, 4:10 PMChisomo Chiweza
12/25/2022, 4:10 PMephemient
12/25/2022, 4:10 PMephemient
12/25/2022, 4:12 PMChisomo Chiweza
12/25/2022, 4:17 PMJan Durovec
12/25/2022, 4:42 PMfold
/`reduce`/...)
• As for missing features (judging by what I've addded to my utils), probably
◦ richer math (gcd
, lcm
, rational numbers with arithmetic)
◦ point2d, point3d, Manhattan distance
◦ IntProgression.size
◦ split
on List
(ideally with the option whether to keep or drop separator)
However, all that can be rather easily added so overall I was satisfied with language features and the code was readable and concise.
I was struggling a bit with inability to add static members to nested/inner classes but only because of the fact that the sample template did not wrap each day in a separate package/class (otherwise I would be able to declare top-level classes without having to worry about namespace clashes).
Oh... and definitely private type aliases scoped to just a file so that they don't collide across days ie as they should work as per spec (https://youtrack.jetbrains.com/issue/KT-17699) (which is also solvable by putting individual days in separate packages)Olaf Gottschalk
12/25/2022, 4:45 PMOlaf Gottschalk
12/25/2022, 4:49 PMJon Senchyna
12/25/2022, 5:15 PMobject.run { copy(foo = foo.run { copy(...) } ) }
ephemient
12/25/2022, 5:48 PMJakub Gwóźdź
12/25/2022, 6:30 PMJonathan Kolberg
12/25/2022, 7:27 PMJakub Gwóźdź
12/26/2022, 12:10 PMparallelStream
in java. I know there are flows, channels and whatnot (I did aoc2019 with them) but they are so far from idiomatic kotlin that each time I consider using them, I ask myself a question: Do I want to spend half a day now re-learning that API (and then worry if my solution does not work because it’s bad or because I misconfigured coroutines).ephemient
12/26/2022, 3:10 PMwithContext(Dispatchers.Default) {
inputs.map {
async { computation(it) }
}.awaitAll()
}
Jakub Gwóźdź
12/26/2022, 3:13 PMzokipirlo
12/26/2022, 3:26 PMephemient
12/26/2022, 5:46 PMsuspend fun main
nkiesel
12/27/2022, 3:09 AMJakub Gwóźdź
12/27/2022, 7:53 AMephemient
12/27/2022, 8:07 AMjava.util.*
? unless you're targeting multiplatform like I wasAlyssa Burlton
12/27/2022, 1:29 PMInt
overflows would be incredible, although I know this is something inherited from the JVM so it might not be possible. I unexpectedly ran into this in the first part of the monkeys-throwing-items puzzle and it took me ages to work out that was the problem (there was only one item in my input that overflowed at one moment in the sequence, so my answer was v. close to being right and manual stepping through looked like it was doing the right stuff).
I know there are "safe" ways to write code to work around it, but that still means remembering to write special code where really you just want to write simple arithmetic and have something automatic tell you if you're overflowing. And opting to always write with Long
isn't amazing either, due to fiddliness mentioned by others (having to stick L
on the end of constants, and converting between stdlib things that return Int
such as list sizes/indices etc). Having a runtime flag like --error-on-arithmetic-overflow
or something that threw a RuntimeException whenever this happened would be fantastic.Jakub Gwóźdź
12/27/2022, 1:33 PMJonathan Kolberg
12/27/2022, 1:36 PMAdam S
12/27/2022, 3:25 PMephemient
12/27/2022, 6:55 PMephemient
12/27/2022, 6:57 PMephemient
12/27/2022, 6:58 PMUInt
depends on Int
overflow behaviorephemient
12/27/2022, 7:03 PMephemient
12/27/2022, 7:07 PMCognitive Gear
12/28/2022, 9:49 AMAdam S
12/28/2022, 10:30 AMval shouldBeASet: Set<Integer> = setOf(1).filter { it == 1 }
Adam S
12/28/2022, 10:46 AMby lazy {}
delegate)
Both of these (as well others like BigDecimal, a tree structure, sorted list, priority queue, etc) can be implemented manually, but AOC is on the line between “implementing X myself would be easy, but more difficult than this actual challenge - and I don’t want to introduce a bug!”
Plus, especially with AOC, it’s nice to have code that’s contained within a single file without external libraries, and also if the stdlib provides it then I can better read & understand code from others, who might have some custom implementation.Jakub Gwóźdź
12/28/2022, 12:47 PM.map {…}
should not change number of elements in a collections. and since setOf(2, 4, 6, 8, 10).map {it/3}
returns [0, 1, 2, 2, 3]
, it needs to be a List
, to be able to contain both 2
sRoland Yeghiazaryan
12/28/2022, 1:07 PMwindowed
, intersection
and chunking
KCognitive Gear
12/28/2022, 1:41 PMephemient
12/28/2022, 1:56 PM.mapTo(mutableSetOf()) { ... }
or buildSet { .mapTo(this) { ... } }
"missing" 5, how?
both "missing" 2 and 6 should be external libs. there's already several, https://kotlinlang.org/docs/data-science-overview.html#kotlin-librariesephemient
12/28/2022, 1:59 PMephemient
12/28/2022, 2:07 PMabstract class Memo<T, R> : (T) -> R {
private val cache = mutableMapOf<T, R>()
override fun invoke(key: T): R =
cache.getOrPut(key) { compute(key) }
abstract fun compute(key: T): R
}
fun <T, R> Memo(compute: (T) -> R): Memo<T, R> = object : Memo<T, R>() {
override fun compute(key: T): R = compute(key)
}
is doable but figuring out an API to handle different cache eviction policies and and thread safety modes... not sure obviousAlyssa Burlton
12/28/2022, 5:07 PMbig integers are never necessary for AOC thoughtell that to 2019 day 22 😈
ephemient
12/28/2022, 5:11 PMAlyssa Burlton
12/28/2022, 5:15 PMLong
, had to move to big integers to get the right answer. But many years ago now, not about to re-open that can of worms 🪱 🙈ephemient
12/28/2022, 5:50 PMjava.*
references, that's all possible in pure Kotlin now)elizarov
01/10/2023, 9:22 AMproperMod
. There is mod
in the standard library: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/mod.htmlAdam S
01/10/2023, 9:42 AMmod
in stdlib in 2019?elizarov
01/10/2023, 9:44 AM