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, this kata's description is just written too poorly. Additionally, I don't think the test cases are all correct (for JavaScript at least).
Consider this:
Looking at the primes in
gn(104)
give:Sorting and removing duplicates yields
So, if you want us to define a function
p(n)
that returns n unique primes, it might make sense whereHowever, if you look at the primes in
gn(105)
, you getRemoving duplicates and sorting yields
So in this case, using a larger
n
in ourgn(n)
function gave us more primes (in this case, it added 7). So who's to say thatp(6)
shouldn't beThat satifies the definition of "return n unique prime numbers."
Not knowing how to seed the
gn(n)
function gives us a non-deterministicp(n)
, which makesmaxp(n)
just trying to guess what you want.Not to mention, I have no idea what
anOver(n)
is supposed to do, as well asanOverAverage(n)
This comment is hidden because it contains spoiler information about the solution
I like this one the best, this kata screams for recursion, and you hit the nail on the head.
Here is how it "snakes" through this sample city each step of the way (notice how the 8's on the right side don't get infected):
Seriously, this part is really dumb. Why would [2,4] return [2,null]? Why should it return [2,2]?
Probably because their internal test uses some dumb recursive method that doesn't take this in consideration.
This comment is hidden because it contains spoiler information about the solution
I agree, this is a bit silly. I am only using ONE Math.sqrt() call. I calculate my determinant, then create
var root = Math.sqrt(determinant);
How is that FIVE calls? I am calling it once in the function.I did a similar thing. The rows and cols were pretty easy, but the boxes was def trickier. I knew I could loop through them all once and get the rows and cols, but I didn't want do loops through the board a 2nd time just to get the boxes. I figured if I'm looping through it, then there should be a way to map my loop variables to the indeces I needed.
I like how you check row1, col1, and box1 and immediately return false if they don't work. That way you don't need to compute row1, row2, row3, ..., col1, col2, col3, ..., and box1, box2, box3..., THEN start checking those (which is what I did).
Nicely done!
I ran some performance tests on some of the cases (as well as my own solution). The top solution using reduce() performs the worst. The best solution is the one using modulus to loop through the numbers. I was actually surprised my solution did as well as it did since I used Math.pow() which I know can be expensive.
http://jsperf.com/sum-digits-of-a-number