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.
there was a bug in the random tests, due to careless division that could yield a NaN when the length of the array is
0
. can you check if it is good for you know ?Thanks, looking back it's most probably too clever. Negative detection could simply be xneg = (x < 0); more readable and code generation would be same or better because it wouldn't confuse optimizers about the intent.
Despite its name, the C standard does not mandate that implementations of
qsort()
use the quicksort algorithm. In fact, it does not even require aO(n log n)
complexity forqsort()
, though of course most clibs will make it as fast as possible because it is an important function. So you cannoy rely on its stability.That being said, it seems like the glibc standard library (the one used on Codewars, which runs on Linux) uses mergesort in most cases; and "most merge sort implementations produce a stable sort". Do not rely on it though, it is an implementation detail. If you need a stable sort, make it stable yourself, e.g. by comparing the pointers themselves in case of structural equality.
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
This may give you some insights
Merged recently on C standard
This comment is hidden because it contains spoiler information about the solution
Thank you! These days I wouldn't even abbreviate the loop counters, I'd write
day
andweek
instead ofd
andw
. This solution must be almost 10 years old. I have absolutely no memory of doing this kata..