Ryan is an engineer in the Sacramento Area with a focus in Python, Ruby, and Rust. Bash/Python Exercism mentor. Coding, physics, calculus, music, woodworking. Looking for work!
Hi Tom! Thanks for sharing! How does this Gem handle collisions? One of the test cases generates all 676,000 robot names, so if calling random_example provides duplicates, we run into the same "theoretical infinite time complexity" issue, calling random_example repeatedly until it provides the one robot name we haven't encountered yet.
You could use Regexp#random_example in conjunction with the taken_names, as per your first solution in this blog post.
Or -- with the potential performance issue of storing a large array in ruby memory (as with all your other examples that use to_a!) -- you could also use Regexp#examples to end up with very similar solutions. (See the documentation.) For example:
.
...Note that this would be a bad idea if the pattern got longer, so the number of possible results was much larger. All of your examples that use to_a, just like my Regexp#examples code above, would soon freeze the system as the array length grows exponentially.
Using Regexp#random_example - similar to your original implementation - would scale fine though.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Hi Tom! Thanks for sharing! How does this Gem handle collisions? One of the test cases generates all 676,000 robot names, so if calling
random_example
provides duplicates, we run into the same "theoretical infinite time complexity" issue, callingrandom_example
repeatedly until it provides the one robot name we haven't encountered yet.You could use
Regexp#random_example
in conjunction with thetaken_names
, as per your first solution in this blog post.Or -- with the potential performance issue of storing a large array in ruby memory (as with all your other examples that use
to_a
!) -- you could also useRegexp#examples
to end up with very similar solutions. (See the documentation.) For example:.
...Note that this would be a bad idea if the pattern got longer, so the number of possible results was much larger. All of your examples that use
to_a
, just like myRegexp#examples
code above, would soon freeze the system as the array length grows exponentially.Using
Regexp#random_example
- similar to your original implementation - would scale fine though.