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.
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.
Kata.Square
should accept adouble
and return adouble
.It is unfortunate that the description does not make this clear, and that all the example tests pass
int
s which are silently up-cast.Why's that?
Fun fact: You can pull that all the way down to 765 states if you employ a little symmetry breaking.
I am certainly not opposed to retiring the kata if that's the best idea.
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.
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
forn = 2
and the random tests technically could test that, lol. You have a point...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:
-1
should be returned if no magic index exists[]
(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 indexThings I did not do:
For a 7-kyu I think allowing linear solutions is fine; there are no explicit performance requirements on the kata.
Disagree. How would we tell then if the sum of our array was actually zero or if it was an error?
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
Same issue in C.
@hobovsky noted this issue 5 years ago to think about, but perhaps they are still thinking :D
Agree with this criticism.
[Edit] not sure it's an issue though
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.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.@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
we have valid boundaries like so:
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 byoffset
.So for
length = 2, offset = 1
we do:and for
length = 1
we do:and it then follows that for the empty window, we do:
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...