Ad
  • Custom User Avatar
  • Custom User Avatar

    I'm confused by one thing in the problem description: it seems to me that each 'iteration' of altering the population

    1. picks two existing chromosomes (with roulette wheel selection)
    2. duplicates them (the word 'duplicate' is in the description)
    3. for the two new duplicate chromosomes, crossovers (might?) happen (mutation also might happen but is irrelevant to my question)
    4. repeat "until you have a new population the same size as the original one."

    But how can you have a population the same size if every iteration always increases the population by two?
    What am I missing?

  • Custom User Avatar

    Your solution has a high time complexity. If you don't know what that is, now would be a good time to find out, since you're 4kyu.

  • Custom User Avatar

    This is beautiful and would be greatly improved if it was production code with one comment.

    Here's why: the code would be broken if at ANY point any of the 'subtraction' tokens came before the un-modified token.

    What I mean is: if C was listed in the hash before CM, or I before IV, and so on.

    In fact, this code also relies on the fact that Ruby maintains hash order, but that is not strictly guaranteed by MRI. However, in practice I don't think anyone runs into hash order being a problem.

    No, my main concern was that there should be a comment to the effect "Make sure subtraction tokens are listed before un-modified tokens (e.g. C before CM, I before IV)".

  • Custom User Avatar

    I think the kata description should specify that it should be able to handle arrays as well as strings.

  • Custom User Avatar

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

  • Custom User Avatar

    The problem statement implies m will be nonzero: "Your task is to return to the function seven(m) (m integer >= 0)"

    The problem statement should be reworded if the input can be negative.

  • Custom User Avatar

    It's worse than that--the problem statement implies that m will be nonzero: "Your task is to return to the function seven(m) (m integer >= 0)"