279
Infallible Code (feddit.uk)
you are viewing a single comment's thread
view the rest of the comments
[-] _cnt0@sh.itjust.works 3 points 1 week ago

Not to take from all the funny answers ... but

bool IsEven(int i) => (i & 1) != 1;

(C#)

[-] _cnt0@sh.itjust.works 2 points 1 week ago

Though, obviously I had to come up with some ridiculous solutions:

bool IsEven(int i) => ((Func<string, bool>)(s => s[^1] == 48))($"{i:B}");

This one works without conditionals :)

bool IsEven(int i)
{
    try
    {
        int _ = (i & 1) / (i & 1);
    }
    catch (Exception)
    {
        return true;
    }

    return false;
}
[-] Lemminary@lemmy.world 1 points 1 week ago

s[^1]

Ohh wow, I've been learning it casually for years, and I didn't know that existed in C#. I guess I should go back and hit the books some more.

this post was submitted on 15 Jul 2025
279 points (94.3% liked)

Programmer Humor

25180 readers
1758 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 2 years ago
MODERATORS