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.
Dang this is recursion at its best... Kudos to you clever sirs.
Oh snap... My bad. Just re-tested it on
Java
and it seems fine.However, writing the equivalent function in
Python
seems to spit out9
forinput = 0
. That is strange and makes me wonder how different languages implement modulo operations. Very trippy.Sorry to the numerous warriors who were alarmed by my ignorance! I only cared to quickly test it in
Python
.Again, apologies!
This is actually wrong. If the input is
0
the answer would be0
. But this would spit out9
if the input is0
.I suggest the numerous authors to revise this solution by adding an
if
statement for the special case0
.I agree. I was coding up my solution to this problem using functions I have written before, but they were written for
int
so I had to change/refactor my functions to be compatible tolong
.Do you know any way to make functions taking numeric inputs generic for
int
,long
,short
,BigInteger
, etc.?Hmmm. Hard to say. Did some microbenchmark tests, and sometimes the bitwise operation is faster, and sometimes the old fashioned exponential computation is faster. And I simulated very many trials with a wide range of powers, so I doubt there is any benefit to using the bitwise operation.
Other than being fun-spritied, I wouldn't really dub this a very readable code, since not many people know the bitwise operator in Python.