459
you are viewing a single comment's thread
view the rest of the comments
[-] redxef@feddit.org 38 points 5 days ago
def is_even(n: int) -> bool:
    if n < 0:
        return is_even(-n)
    r = True
    for _ in range(n):
        r = not r
    return r
[-] OddMinus1@sh.itjust.works 3 points 4 days ago* (last edited 4 days ago)

Could also be done recursive, I guess?

boolean isEven(int n) {
  if (n == 0) {
    return true;
  } else {
    return !isEven(Math.abs(n - 1));
  }
}
[-] dragonlobster@programming.dev 2 points 4 days ago

He loves me, he loves me not

[-] vandsjov@feddit.dk 1 points 5 days ago

No, no, I would convert the number to a string and just check the last char to see if it was even or not.

this post was submitted on 15 Jul 2025
459 points (94.7% liked)

Programmer Humor

37286 readers
25 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 6 years ago
MODERATORS