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 did the same solution. I guess they would rather see some clean code than efficient code.
Can someone explain this in more detail? I tested this solution with greater-than-16-character strings, and it seems to work fine.
EDIT - I think I got it, the sum method represents its return value as a 16-bit integer by default, so if the sum of the ascii values is greater than 65,535, the sum will overflow and start over from 0. You can pass an optional argument to the sum method to increase this though. 'Hello world'.sum(32) will use a 32-bit integer to represent the checksum. Am I understanding that correctly?
I'm gonna give this one a vote for best practice. It's actually really expressive if you're familiar with the methods being used. And even if you're not, it's concise enough that you can look it up pretty quickly.
Thanks :)
Nice, I didn't know about the
cycle
method.So cool.
This comment is hidden because it contains spoiler information about the solution
It doesn't work for strings with more than 16 characters.
That's why I upvoted it as clever.
What about this solution is incorrect, though?
... until you realize that this solution is wrong and it's far from obvious what that method returns. The solution is still clever and shows the lack of tests, though.
And this is why I love Ruby.
Lame joke accepted ;)
Oh, for sure! I actually think your solution is pretty great (although I'm still not 100% sure I know exactly how it works, haha). I just couldn't pass up the chance to make a lame joke as it related to the problem description.
Oh, rest assured that in production I will never do that (and actually I am usually the one commenting the most), but here is competitive coding: you are meant to show off a bit, plus I found juggling with more things in one line it is great practice.
Consinder it like training with extra weight ;)
And I just noticed I could simplify things much further, as you don't actually need
||[]
on Ruby, ops!/me goes back training in the hyperbolic time chamber
Love me a clever one liner. Although if I had to deal with this in a codebase somewhere I think I would be the one throwing up ;)