Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
Nice kata, thanks!
assertEquals
is Kotlin sample tests should probably beassertEquals("Code: $code", expected, actual)
This comment is hidden because it contains spoiler information about the solution
Thanks for kata! :)
Maybe there should be some tests for
m1 * ... * mk == n
case? Don't see them in Kotlin version.It's great! How did you derive this formula?
val sumRight = sumTotal - sumLeft - value
, sosumLeft == sumRight
is equivalent tosumLeft * 2 + value == sumTotal
This is elegant, but not efficient: O(n^2) time & space complexity instead of O(n).
These "you-are-an-idiot" replies do not help much. ;)
If you don't want to give any hints... well, it's your right. But if a kata does not allow to learn something new, what's the purpose?
What resources to learn Kotlin better can you suggest? AFAIR, "Kotlin in Action" does not cover anything like this.
Bonus question: in which cases such tricks may be useful in real life?
This kata (in Kotlin version) looks very strange:
operArray(this::som, a, 0)
som
ormax
do not make much sensereduce
should return a single value. In this kata we have to invent an ugly hybrid ofmap
andreduce
.a
means two different things in the same line. This is obscure and generally not good.What are we supposed to do in this cata? The only "extension constructor" for Int I can imagine is
fun Int(s: String) = s.toInt()
, but the tests specifically use kotlin.Int(). So the most meaningful way to "make them pass" is to change the tests themselves. Or should we hack into standard library with e.g. reflection?This comment is hidden because it contains spoiler information about the solution
It seems that Kotlin random tests are incorrect: they mutate passed array, so the function under test receives array where first and last elements are already swapped. Random tests really verify that the function returns passed array (modified or not) or its unmodified copy. To pass both random and basic tests (which are correct), we need to mutate passed array again and return it.
If this is intended, this is worth adding to kata description. But I suppose mutating passed arrays is generally not a best practice, so I would prefer this kata (7 kyu = for junior developers) to explicitly require non-mutating solution, and to test this fact too.
Anyway, thanks for the kata. :)
This is probably the fastest solution, but requires Java 8 (which might be a problem e.g. on Android). One minor note: Math.abs is redundant here. ;)
For Kotlin
input
type should be nullable (Array<Int>?
instead ofArray<Int>
), otherwise tests do not compileMy first solution used only one dimension and passed all the tests. A think some tests with x = 0 or y = 0 should be added to prevent it.
This comment is hidden because it contains spoiler information about the solution
Loading more items...