Thanks for mentioning. I am new on this platform and didn't know the purpose of spoiler flag. Now I knnow. Thanks :)
Use spoiler flag, please.
This comment is hidden because it contains spoiler information about the solution
You get this error when you pass a negative value to Math.sqrt. You can't pass negative to it.
i agree, for example 1e16+1 returns true when it shouldn't
@Wei-LiangChew I'm a little late but then the while loop will iterate over with n - 1 = 8 (and so on)
hmm.. i kept getting sqrt error. not sure why. thought Math.sqrt isn't supported here.
But what if the largest 5-digit number in digits doesn't start with 9?
This is better than using array.shift because it leaves array unaltered.
Or do variables duplicate when put as arguments anyway?
I'm going to say the same thing others have said...
I don't think it makes sense to disallow the use of alias_method if they aren't creating a unique method. This asks users to create an alias for a method while preventing them from using best practices. For newer programmers this could potentially teach them bad practices or confuse them on what the best practices are.
I recommend allowing the use of alias_method if the goal is to have users alias a method, or have them add a simple method like String#first or String#last to return the first or last character.
Nice one-liner. The Array allocated by split('') or chars gives this algorithm O(n) space complexity, it's possible to solve this with O(1) space complexity. All voted on solutions share this problem.
This is awesome!
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 ?