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.
I should clarify how I got to this solution. My first attempt at this was
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.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 ofpresidents
, but if I copy/paste the data frame definition from the instructions to the sample tests area, everything runs fine.The fact that only distinct elements are considered when calculating the nth smallest element needs to be mentioned.
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.
The description needs some updating:
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.
All looks well now. Solutions that used the
**
operator are now invalid, while the others are still valid.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: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 withx.gmtime.strftime("%I:%M:%S")
. I wonder if it may be best to allow for +/- 1 second.Let me know if these couple of hints help:
Yeah, ternary operator.
Would you mind posting what you have for a solution?
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).
This comment is hidden because it contains spoiler information about the solution
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...