Ad
  • Custom User Avatar

    You are not supposed to convert between strings and integers at all (unless maybe for debugging purposes). If you really, really, really want to you can use the fact that the length of string is given as a parameter in run_fitness.

  • Custom User Avatar

    Yeah, about that. I understand that it is confusing. Since we have arbitrarily large integers in Ruby we use integers instead of strings.
    The description states: "What the test will do is generate a random binary string of 35 digits (a random Integer with 35 bits for Ruby)".
    You are not the first person to ask about this, and probably not the last.
    Could you please help and make the description more clear?

  • Custom User Avatar

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

  • Custom User Avatar

    A ; in Ruby is the equivalent to a line break. The author uses it so that the block returns h instead of whatever h[w] += 1 would return. What the .inject and its block does in this solution is usually written like this in Ruby:
    each_with_object(Hash.new(0)) { |w, hsh| hsh[w] += 1 }
    This is a tiny bit more readable, but does on the other hand take 8 characters more to type.

  • Custom User Avatar

    And also: Although perfectly legal, why start with 8 balls? Why not have the entire span of 0 to 500 instead? Seems somewhat arbitrary to pick 8 as the starting number.

  • Custom User Avatar

    I've not yet done this kata, but in the description it says: "(ball count) 0-9 | (uses) 2".
    Shouldn't it be "1 | 0", "2-3 | 1" and "4-9 | 2"?

  • Custom User Avatar

    Yes fitness[i] is the fitness of chromosome[i].
    It looks like you are doing this in Ruby. In that case you should use an integer instead of a binary string.
    The description states: "What the test will do is generate a random binary string of 35 digits (a random Integer with 35 bits for Ruby)".
    So in Ruby we use Integers instead of strings (since we have Integers of arbitrarily large size already).

  • Custom User Avatar

    Yes, it should be possible to solve in Ruby at this point.

    The description states: "and an optional number of iterations (default to 100)" meaning that your run method should work with 4 as well as 5 parameters.

  • Custom User Avatar

    When making a new kata in the kata editor, the "example test cases" does not save.

    Steps to reproduce:

    1. Go to http://www.codewars.com/kata/new
    2. Press "Example Test Cases"
    3. Write an example test case.
    4. Press "Save".
    5. Your example test case are nowhere to be found.

    This problem can not be reproduced with "Test Cases", "Preloaded", "Initial Solution", "Complete Solution" or "Description".

  • Custom User Avatar

    I've started a Ruby translation. Help and opinions are very welcome. :)
    I am quite new to Ruby. It would be awesome if someone more experienced could help out and get the translation in good quality enough to be accepted by author/mods.

  • Custom User Avatar

    This is with Integer instead of bit string. (Is easier and better for Ruby I think.)

  • Custom User Avatar

    I want to see this Kata in Ruby, so I started a translation.
    Right now the translation is very close to the original, but there are some points that could be made more Ruby-esqe.
    I would very much like input on this, since I am quite new to Ruby.

    • Ruby has arbitrarily large integers. Therefor "bit string" would make little sense and most people would've probably just used an integer instead.
    • When a lambda/Proc is passed to a function it's usually as the last argument (I think). Now I just kept the same order of arguments as in the Javascript version.
    • GeneticAlgorithm not a class. Since it doesn't need to initialize, and doesn't save any data I think it's debatable if it should be a class or not.

    I also wonder if this is really the best case to show genetic programming. This example doesn't have any local maximi except for the global one. So crossover is really not that useful. Well, I had tons of fun anyway! Thanks!

  • Custom User Avatar

    Thank you. Excellent explanation. :)

  • Custom User Avatar

    Where do I press to upvote katas?

  • Custom User Avatar

    This could use some more test cases.

  • Loading more items...