Infallible Code
Infallible Code
Infallible Code
You're viewing a single thread.
python
def is_even(n: int) -> bool: if n < 0: return is_even(-n) r = True for _ in range(n): r = not r return r
Could also be done recursive, I guess?
java
boolean isEven(int n) { if (n == 0) { return true; } else { return !isEven(Math.abs(n - 1)); } }
He loves me, he loves me not
No, no, I would convert the number to a string and just check the last char to see if it was even or not.