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

Programmer Humor

37227 readers
22 users here now

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

Rules:

founded 6 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
[–] Aedis@lemmy.world 33 points 2 days ago (13 children)

I'm partial to a recursive solution. Lol

def is_even(number):
    if number < 0 or (number%1) > 0:
        raise ValueError("This impl requires positive integers only") 
    if number < 2:
        return number
    return is_even(number - 2)
[–] tetris11@lemmy.ml 18 points 2 days ago* (last edited 2 days ago) (12 children)

I prefer good ole regex test of a binary num

function isEven(number){
   binary=$(echo "obase=2; $number" | bc)
   if [ "${binary:-1}" = "1" ]; then
         return 255
   fi
   return 0
}
load more comments (10 replies)
load more comments (10 replies)