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.
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
.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?
This comment is hidden because it contains spoiler information about the solution
A
;
in Ruby is the equivalent to a line break. The author uses it so that the block returnsh
instead of whateverh[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.
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.
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"?
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).
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.When making a new kata in the kata editor, the "example test cases" does not save.
Steps to reproduce:
This problem can not be reproduced with "Test Cases", "Preloaded", "Initial Solution", "Complete Solution" or "Description".
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.
This is with Integer instead of bit string. (Is easier and better for Ruby I think.)
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.
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!
Thank you. Excellent explanation. :)
Where do I press to upvote katas?
This could use some more test cases.
Loading more items...