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.
🫡
I finally understand recursion.
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 😅
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
It is an old post because the "is even" algorithm keeps being posted to this sub every month or so.
I created my own toy interpreted language and I didn't feel like adding the modulas operator at the time(And it obviously didn't have the bitwise operators) So I ended up using this exact method lol
Almost there. Just needs some memoization!
Make sure you return math.abs(num-2) so it works with negative numbers
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!
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?
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.
It rents a cloud server and keeps going
Then you download more
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
Are you the intern at work, by any chance?