Ad
  • Default User Avatar

    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:

    [5, 3, 11, 3, 23, 3, 47, 3, 5, 3, 101, 3]
    

    Sorting and removing duplicates yields

    [3, 5, 11, 23, 47, 101]
    

    So, if you want us to define a function p(n) that returns n unique primes, it might make sense where

    p(6) = [3, 5, 11, 23, 47, 101];
    

    However, if you look at the primes in gn(105), you get

    [5, 3, 11, 3, 23, 3, 47, 3, 5, 3, 101, 3, 7]
    

    Removing duplicates and sorting yields

    [3, 5, 7, 11, 23, 47, 101];
    

    So in this case, using a larger n in our gn(n) function gave us more primes (in this case, it added 7). So who's to say that p(6) shouldn't be

    p(6) = [3, 5, 7, 11, 23, 47];
    

    That satifies the definition of "return n unique prime numbers."

    Not knowing how to seed the gn(n) function gives us a non-deterministic p(n), which makes maxp(n) just trying to guess what you want.

    Not to mention, I have no idea what anOver(n) is supposed to do, as well as anOverAverage(n)

  • Default User Avatar

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

  • Default User Avatar

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

    var city = [
     [8, 8, 8, 8, 8, 7, 8],
     [1, 1, 1, 1, 8, 7, 8],
     [8, 8, 8, 1, 8, 7, 8],
     [8, 1, 1, 1, 8, 7, 8],
     [8, 8, 8, 8, 8, 7, 8]];
    
    [[1,0,0,0,0,0,0],
     [0,0,0,0,0,0,0],
     [0,0,0,0,0,0,0],
     [0,0,0,0,0,0,0],
     [0,0,0,0,0,0,0]]
    
    [[1,1,0,0,0,0,0],
     [0,0,0,0,0,0,0],
     [0,0,0,0,0,0,0],
     [0,0,0,0,0,0,0],
     [0,0,0,0,0,0,0]]
    
    [[1,1,1,0,0,0,0],
     [0,0,0,0,0,0,0],
     [0,0,0,0,0,0,0],
     [0,0,0,0,0,0,0],
     [0,0,0,0,0,0,0]]
    
    [[1,1,1,1,0,0,0],
     [0,0,0,0,0,0,0],
     [0,0,0,0,0,0,0],
     [0,0,0,0,0,0,0],
     [0,0,0,0,0,0,0]]
    
    [[1,1,1,1,1,0,0],
     [0,0,0,0,0,0,0],
     [0,0,0,0,0,0,0],
     [0,0,0,0,0,0,0],
     [0,0,0,0,0,0,0]]
    
    [[1,1,1,1,1,0,0],
     [0,0,0,0,1,0,0],
     [0,0,0,0,0,0,0],
     [0,0,0,0,0,0,0],
     [0,0,0,0,0,0,0]]
    
    [[1,1,1,1,1,0,0],
     [0,0,0,0,1,0,0],
     [0,0,0,0,1,0,0],
     [0,0,0,0,0,0,0],
     [0,0,0,0,0,0,0]]
    
    [[1,1,1,1,1,0,0],
     [0,0,0,0,1,0,0],
     [0,0,0,0,1,0,0],
     [0,0,0,0,1,0,0],
     [0,0,0,0,0,0,0]]
    
    [[1,1,1,1,1,0,0],
     [0,0,0,0,1,0,0],
     [0,0,0,0,1,0,0],
     [0,0,0,0,1,0,0],
     [0,0,0,0,1,0,0]]
    
    [[1,1,1,1,1,0,0],
     [0,0,0,0,1,0,0],
     [0,0,0,0,1,0,0],
     [0,0,0,0,1,0,0],
     [0,0,0,1,1,0,0]]
    
    [[1,1,1,1,1,0,0],
     [0,0,0,0,1,0,0],
     [0,0,0,0,1,0,0],
     [0,0,0,0,1,0,0],
     [0,0,1,1,1,0,0]]
    
    [[1,1,1,1,1,0,0],
     [0,0,0,0,1,0,0],
     [0,0,0,0,1,0,0],
     [0,0,0,0,1,0,0],
     [0,1,1,1,1,0,0]]
    
    [[1,1,1,1,1,0,0],
     [0,0,0,0,1,0,0],
     [0,0,0,0,1,0,0],
     [0,0,0,0,1,0,0],
     [1,1,1,1,1,0,0]]
    
    [[1,1,1,1,1,0,0],
     [0,0,0,0,1,0,0],
     [0,0,0,0,1,0,0],
     [1,0,0,0,1,0,0],
     [1,1,1,1,1,0,0]]
    
    [[1,1,1,1,1,0,0],
     [0,0,0,0,1,0,0],
     [1,0,0,0,1,0,0],
     [1,0,0,0,1,0,0],
     [1,1,1,1,1,0,0]]
    
    [[1,1,1,1,1,0,0],
     [0,0,0,0,1,0,0],
     [1,1,0,0,1,0,0],
     [1,0,0,0,1,0,0],
     [1,1,1,1,1,0,0]]
    
    [[1,1,1,1,1,0,0],
     [0,0,0,0,1,0,0],
     [1,1,1,0,1,0,0],
     [1,0,0,0,1,0,0],
     [1,1,1,1,1,0,0]]
    
  • Default User Avatar

    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.

  • Default User Avatar

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

  • Default User Avatar

    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.

  • Default User Avatar

    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!

  • Default User Avatar

    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