81 points

Incoming trademark lawsuit from iSeven, the API that tells you if a number is seven or not

permalink
report
reply
57 points
*

If anyone wants a more efficient local version for php:

function isEven(int $number): bool
{
    ${1} = false;
    ${2} = true;

    while ($number > 2) {
        $number -= 2;
    }

    return $$number;
}

Edit: Now with support for large numbers!

function isEven(int|string $number): bool
{
    ${1} = false;
    ${2} = true;

    while (bccomp($number, 2) === 1) {
        $number = bcsub($number, 2);
    }

    $number = (int) $number;
    return $$number;
}

Edit 2: someone asked for an ad-supported version, here you go!

function isEven(int|string $number): bool
{
    ${1} = false;
    ${2} = true;

    while (bccomp($number, 2) === 1) {
        error_log('Buy isEvenCoin, the hottest new cryptocurrency!');
        $number = bcsub($number, 2);
    }

    $number = (int) $number;
    return $$number;
}

Side note, no more suggestions please, this is getting quite long.

permalink
report
reply
16 points
*

I fucking love that you managed to use var-vars in a completely key and necessary manner.

But please do adhere to the API TOS and throw in an error_log('Buy isEvenCoin, the hottest new cryptocurrency!');

permalink
report
parent
reply
12 points

This looks pretty inefficient. You should manually unroll that loop to improve performance.

permalink
report
parent
reply
10 points

Comment edits are the best version control system

permalink
report
parent
reply
5 points

I agree! Added new commit to my comment.

permalink
report
parent
reply
54 points

Oh, bummer, my number isn’t supported by the free version:

https://api.isevenapi.xyz/api/iseven/8764389587485736749956772984692357867345989845699872561/

permalink
report
reply
46 points

Just divide that number by two until it’s small enough to make the request under the free version.

permalink
report
parent
reply
40 points

pretty sure that has to be against their TOS

/s

permalink
report
parent
reply
3 points

That’s against the terms of math :-)

permalink
report
parent
reply
19 points

That’s not even supported by the enterprise version. You’re going to need a special agreement with the iseven people to support numbers like that

permalink
report
parent
reply
6 points

Easy workaround, just test the last digit. If it is even, the entire number is even, else odd.

permalink
report
parent
reply
12 points

That’s preposterous! Next time you’ll tell me the language I’m using has a builtin operator that test if a number can be divided by another!

permalink
report
parent
reply
37 points

Only way it could be better is if they threw “AI” in there somewhere.

permalink
report
reply
32 points

With the new AI integration, you can get smart isEven results that return the correct answer 90% of the time and a more creative solution 20% of the time.

permalink
report
parent
reply
28 points

im glad that people are out there building the web services we truly need.

permalink
report
reply

Programmer Humor

!programmer_humor@programming.dev

Create post

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

  • Keep content in english
  • No advertisements
  • Posts must be related to programming or programmer topics

Community stats

  • 3.4K

    Monthly active users

  • 1K

    Posts

  • 38K

    Comments