Ad
  • Custom User Avatar

    I should clarify how I got to this solution. My first attempt at this was

    sumin <- function(n) {
      sum(do.call(pmin, expand.grid(1:n, 1:n)))
    }
    
    sumax <- function(n) {
      sum(do.call(pmax, expand.grid(1:n, 1:n)))
    }
    
    sumsum <- function(n) {
      sum(expand.grid(1:n, 1:n))
    }
    

    but that failed some tests due to overflow (it's obviously a very space-intensive attempt). I then looked at the sequence that results from setting n = 1, 2, ..., 20 in each of these different first-attempt functions (e.g., sapply(1:20, sumin)) and searched for each of those sequences on OEIS (https://oeis.org/). That led me to the closed-form solutions for each of the functions, and thus, this kata solution.

  • Custom User Avatar

    The presidents data frame seems to be broken. As is, I get an error, $ operator is invalid for atomic vectors, when attempting to access a column of presidents, but if I copy/paste the data frame definition from the instructions to the sample tests area, everything runs fine.

  • Custom User Avatar

    The fact that only distinct elements are considered when calculating the nth smallest element needs to be mentioned.

  • Custom User Avatar

    This is very similar to http://www.codewars.com/kata/55eea63119278d571d00006a and while there are differences (this one deals with strings, unique numbers, and possibly invalid arguments; that one deals with lists of ints and possibly duplicate numbers), I wonder if they are enough to warrant two separate katas.

  • Custom User Avatar

    The description needs some updating:

    • Add a note that in the case of two solutions they need to be sorted numerically.
    • Which case should result in 'Impossible situation. Wrong entries' instead of 'The equation is indeterminate'?
  • Custom User Avatar

    There are n nth roots of a number x. The description needs to be changed to state the goal is to calculate the principal nth root of x.

  • Custom User Avatar

    All looks well now. Solutions that used the ** operator are now invalid, while the others are still valid.

  • Custom User Avatar

    Wording in the description looks good to me. The link to the Exponent Method kata seems to be http://www.codewars.com/kata/exponent-method now; the links in the description should be updated.

    It looks like something is broken with the ** disabling. All solutions are now invalid and when attempting to submit a solution, an undefined method error occurs:

     `
    ': undefined method `**' for class `Object' (NameError)
    
  • Custom User Avatar

    For the output, I think specifying that results should be sorted works well. This way the output is always an array of 11 times, as your description now mentions.

    As an aside, another kata could be created as a variation of this one in which only times during the first 12 hours are reported (in order). For small angles, the output would have 11 different times, but as the angles grow larger, the output array grows smaller (e.g., for 540 degrees, only 10 times are output).

    For the rounding issue, I'm also formatting the result with "%I:%M:%S". I'm calculating the seconds as a Time, x, and then formatting with x.gmtime.strftime("%I:%M:%S"). I wonder if it may be best to allow for +/- 1 second.

  • Custom User Avatar

    Let me know if these couple of hints help:

  • Custom User Avatar
  • Custom User Avatar

    Would you mind posting what you have for a solution?

  • Custom User Avatar

    Thanks! I finally got it to work, too. I had implemented a standard roulette wheel selection thinking that it'd be faster to use only two random selections to get the two chromosomes needed, but now I see that while the stochastic method could take many attempts to finally make a selection, the overhead (additional calculations) needed is so much less than the standard selection that it does actually go quite a bit faster. It really does seem that the stochastic version is necessary to allow for the larger population sizes that are needed to converge to the solution fast enough and pass this kata.

    FWIW to anyone, instead of repeatedly trying with one population size, I just kept bumping it up until I got a success. That happened at a size of 250 (and failed at least once with sizes of 100 and 150).

  • Custom User Avatar

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

  • Custom User Avatar

    It is not obvious from the description that numbers and case-insensitive letters are the only things to be considered when checking if the input is a palindrome.

  • Loading more items...