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.
Description updated
@Wei-LiangChew I'm a little late but then the while loop will iterate over with n - 1 = 8 (and so on)
But what if the largest 5-digit number in
digits
doesn't start with 9?Very clever, learned the existence of filter because of this example!
Nice one-liner. The Array allocated by
split('')
orchars
gives this algorithmO(n)
space complexity, it's possible to solve this withO(1)
space complexity. All voted on solutions share this problem.Great Job, I just started to learn regex, and I find it really useful ( rather than iterate over each caracter and check), it could be a little faster if you replace .sort.pop for .max, I'm still not sure how regex does it, because in order to find all chunks starting with 9 and 4 more digits it still needs to iterate over all the array, so Im not sure why my solution is slower, maybe because the regex is executed in a binary library rather than interpreted like ruby ?
Hey, I get your mysterious error too.
Anyway, this solution isn't very efficient so it shouldn't be able to pass. Did you read the hint?
This comment is hidden because it contains spoiler information about the solution
It's giving me an unknown error, but my algorithm is working just fine on my computer, negafibonacci and all!
It's not a method, it's a keyword. It's equivalent to a try/catch statement in some other languages.
This may help:
http://rubylearning.com/satishtalim/ruby_exceptions.html
Damn, I'm stuck! Don't know what to do here at all. Gonna lurk around a little bit, I hope I can make this soon.
Practiced a little bit, learned a lot by your example, thanks!
Can't understand clearly what's going on the gsub, but this is a short and beautiful solution!
I don't know how to use that rescue method there. I can't find any documentation anywhere!
Because an error occurred, maybe? Try
digits.length
Loading more items...