Ad
  • Default User Avatar

    Nice kata, thanks! assertEquals is Kotlin sample tests should probably be assertEquals("Code: $code", expected, actual)

  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Default User Avatar

    Thanks for kata! :)
    Maybe there should be some tests for m1 * ... * mk == n case? Don't see them in Kotlin version.

  • Default User Avatar

    It's great! How did you derive this formula?

  • Default User Avatar

    val sumRight = sumTotal - sumLeft - value, so sumLeft == sumRight is equivalent to sumLeft * 2 + value == sumTotal

  • Default User Avatar

    This is elegant, but not efficient: O(n^2) time & space complexity instead of O(n).

  • Default User Avatar

    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?

  • Default User Avatar

    This kata (in Kotlin version) looks very strange:

    1. Tests use clumsy LongBinaryOperator instead of Kotlin functional features, e.g. operArray(this::som, a, 0)
    2. If we can pass lambda as a parameter, trivial functions like som or max do not make much sense
    3. Kata name is misleading, as reduce should return a single value. In this kata we have to invent an ugly hybrid of map and reduce.
    4. There is a mess with agrument names in tests: a means two different things in the same line. This is obscure and generally not good.
    5. Kata talks about a lot of concepts: "reduce function", "generic functions", GCD/LCM, etc - so its focus is unclear. Kata is not hard, just... strange.
  • Default User Avatar

    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?

  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Default User Avatar

    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. :)

  • Default User Avatar

    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. ;)

  • Default User Avatar

    For Kotlin input type should be nullable (Array<Int>? instead of Array<Int>), otherwise tests do not compile

  • Default User Avatar

    My 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.

  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Loading more items...