this post was submitted on 15 Jul 2025
456 points (95.1% liked)

Programmer Humor

37222 readers
110 users here now

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

Rules:

founded 5 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
[–] redxef@feddit.org 36 points 1 day ago (3 children)
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 21 hours ago* (last edited 21 hours ago) (1 children)

Could also be done recursive, I guess?

boolean isEven(int n) {
  if (n == 0) {
    return true;
  } else {
    return !isEven(Math.abs(n - 1));
  }
}

He loves me, he loves me not

[–] vandsjov@feddit.dk 1 points 1 day 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.