Ad
  • Custom User Avatar

    Sorry @hobovsky, I think there's some confusion. I'm talking about the requirements of the Kata as it stands, not what it might be changed to.

    That said, on review I can see that there is a comment in the initial solution which describes this, so I don't think this counts as a kata issue.

  • Custom User Avatar

    Kata.Square should accept a double and return a double.

    It is unfortunate that the description does not make this clear, and that all the example tests pass ints which are silently up-cast.

  • Custom User Avatar
  • Custom User Avatar

    Fun fact: You can pull that all the way down to 765 states if you employ a little symmetry breaking.

  • Custom User Avatar

    I am certainly not opposed to retiring the kata if that's the best idea.

  • Custom User Avatar

    it is hard to see that the second 2 is the squareroot and not mean

    There is no square root involved; I think you are perhaps misreading?

    If others have similar confusions I suggest you find the definition of population variance on Google.

  • Custom User Avatar

    You're correct, there is no integer base where 2 or 0 is made up of all 1s, and 1 is "all 1s" in every integer base.
    Hence, the kata only requires you to return an answer for n >= 3.

    Edit: Actually the Python reference solution returns 1 for n = 2 and the random tests technically could test that, lol. You have a point...

  • Custom User Avatar

    I've rewritten essentially the whole test suite for this kata and addressed all open issues and suggestions. Fork here:
    https://www.codewars.com/kumite/68704f6003d2af5114b7a9bb?sel=68704f6003d2af5114b7a9bb

    Patch notes:

    • Description updated to correctly note that arrays are zero-indexed, and to explicitly state that -1 should be returned if no magic index exists
    • Sample tests are now all unique, sorted arrays as per the existing description
    • Node version => v18.x
    • Test harness => Mocha + Chai
    • The previous random tests always returned [] (therefore -1 was always the correct return value); random tests now generate random sorted unique arrays of random lengths {0 <= n < 100} with a random chance of containing a magic index
    • Upped the number of random tests from 6 (or 0, really) to 100

    Things I did not do:

    • Implement testing that would force solutions to run in sub-linear time. This is a 7-kyu with no stated performance constraints and I didn't think it was necessary
    • Changed the tags; I don't know how (or even if I can?)
  • Custom User Avatar

    For a 7-kyu I think allowing linear solutions is fine; there are no explicit performance requirements on the kata.

  • Custom User Avatar

    Disagree. How would we tell then if the sum of our array was actually zero or if it was an error?

    sum_array([0, 2, -1, -1]) == sum_array(sum_array) # ??? No thanks
    

    The better way to handle this is to raise an error, or rather in this case just let the error that already exists be raised

  • Custom User Avatar
  • Custom User Avatar

    Agree with this criticism.

    [Edit] not sure it's an issue though

  • Custom User Avatar

    There are bugs in your solution that are causing you to fail the random tests. Inspect the output and try to figure out where you're going wrong.

    The issue flag is for issues with the kata itself, not issues you're having solving it, so I'm resolving this one.

  • Custom User Avatar

    It's just a bit of input validation that you have to do. It's not really relevant to the kata itself but dealing with None/null/null pointers/etc. is a ubiquitous part of programming.

  • Custom User Avatar

    @Spaceman perhaps a different analogy would help - think of the boundaries of the window as existing "between" the indices of the array elements. So for the array

    [0, 1, 2]
    

    we have valid boundaries like so:

    [* 0 * 1 * 2 *]
    

    Then, to construct a window of a given length we place our left boundary, move forward length steps and place the right boundary. To construct the next window we move the left boundary forward by offset.

    So for length = 2, offset = 1 we do:

    [{ 0 * 1 } 2 *]
    [* 0 { 1 * 2 }]
    

    and for length = 1 we do:

    [{ 0 } 1 * 2 *]
    [* 0 { 1 } 2 *]
    [* 0 * 1 { 2 }]
    

    and it then follows that for the empty window, we do:

    [{} 0 * 1 * 2 *]
    [* 0 {} 1 * 2 *]
    [* 0 * 1 {} 2 *]
    [* 0 * 1 * 2 {}]
    

    Even when the set of remaining indices is empty, the empty set is still a valid subset because the empty set is a subset of all sets (including itself).

  • Loading more items...