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.
If only you smarter fellas documented your code. THe world would be perfect. :/
When I tried a solution similar to this, I got a runtime error. Is Character.getNumericvalue(intString.charAt() substantially faster than Integer.parseInt(String.substring())? Or was there perhaps something else that I was missing?
Easier, yes.
Simpler, no: recursion is harder to read, understand and debug.
Faster, barely: log10(n) is only slightly faster than converting to String.
Space efficient, hard no: recursion will alocate more stack space than a string.
Personaly I prefer the solution above more, as it is easier work with(all be at slower).
I cannot see the solution since I have not solved this kata in Java, but the integer part of log10 of a positive integer + 1 is equal to the length of the decimal representation of this number:
Math.floor(Math.log10(n)+1)==n.toString().length
(more or less, sorry if this is not correct, but my Java is not fluent :) ).
can somebody explain why he used that "log10(n)" over there ?
I haven't done any math in like 2 years so I kinda forgot about logs and how they work.
Thanks a lot !
I wrote literally same code without looking at your code xd. Good job!
This can be done much easier without having to convert your int to a string.
good jop but you better get the chars form the string by charArray as .charAt method has a bad complexity :)
Im a little confused as too what your asking. If n is greater than the sum of its digits raised to the (p + i) power, then the final step of (sum % n) will never return 0, causing the method to return -1.
how you check whether n is bigger of sum