Technically correct. Also a speedrun to stack overflow
Some languages will optimize the tail recursion, but not python.
genuinely i sometimes forget that stack overflow is, like, a thing, and not just a website
IsEven(1000000000)
Inside the else
block, you could nest another if/else statement to check if the number is less than 0 and if it is, return isEven(num+2)
, else return isEven(num-2)
.
I only push code that will break with edge cases that aren’t even really edge cases
I finally understand recursion.
🫡
Somebody must’ve screenshotted another PirateSoftware project.
Did you just UperCamelCase a Python function?
Old post.
I just wrote this in my notes app, whatcha on man
may i interest you in other ways to find if a number is even? https://github.com/desaleo/is-even
This is awesome
thank you 😅
Almost there. Just needs some memoization!
Why are we going back to this?
isEven(-8)
Uh? What do you mean that's not how it works?
We just wait out for the overflow
Python 3 ints don't overflow, they just allocate more ram.
What happens if you run out of ram?
then it's odd, or even, it depends on host system
swap
we autoscale machines with more ram and keep going!
Kein Problem. Einfach auf den swap auslagern oder das Programm mit dem Hinweis pausieren das mehr RAM nachgerüstet werden muss. Wenn der swap ausgeht, wird einfach auf die Cloud umgestiegen.
just download more RAM
Is there a python library to automate installing more ram? Or would that be too dangerous, since a script could just download all the ram in the world and everyone else would have none?
Also, python doesn't allow infinite recursion, it has a maximum depth.
How bout abs?
Still too much fat percentage for them to show I'm afraid :P
return IsEven(abs(-8)-2) would work
Edit: Tested and it does. Although can't fathom why not just return num % 2 == 0