Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
error message received when
x > 498:
RecursionError: maximum recursion depth exceeded in comparison
I'm actually somewhat surprised at how fast this is, despite how absolutely terrible it is. The default python recursion depth limit is triggered after x=498 so these functions are kinda useless... unless you know for sure no one would ever try a number larger than 498. -
Root825606y@Supersebi3
`(x&1)==0` is still the fastest. No division, only a single AND and CMP.
Though it's python so it's all interpreted anyway; who knows what instructions the code actually maps to. I really kind of hate interpreted languages because of this. -
That is a nice (useless) demo to show recursion, although is_even wouldn't need to call is_odd.
However, if all calls would be using constants, a C++ recursive template would be fastest:
The compiler would do the math, and would substitute all calls with the results.
That's called TMP.
C++ rocks! 😁
Auuuuu 😢
joke/meme