Lemmings.world
  • Communities
  • Create Post
  • Create Community
  • heart
    Support Lemmy
  • search
    Search
  • Login
  • Sign Up
Mac@programming.dev to Programmer Humor@programming.dev · 1 year ago

isEven API

isevenapi.xyz

external-link
message-square
28
link
fedilink
288
external-link

isEven API

isevenapi.xyz

Mac@programming.dev to Programmer Humor@programming.dev · 1 year ago
message-square
28
link
fedilink
alert-triangle
You must log in or register to comment.
  • 4am@lemm.ee
    link
    fedilink
    arrow-up
    80
    arrow-down
    1
    ·
    1 year ago

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

  • Rikudou_SageA
    link
    fedilink
    English
    arrow-up
    57
    ·
    edit-2
    1 year ago

    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.

    • xmunk@sh.itjust.works
      link
      fedilink
      arrow-up
      16
      ·
      edit-2
      1 year ago

      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!');

    • idunnololz@lemmy.world
      link
      fedilink
      arrow-up
      12
      ·
      1 year ago

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

    • shotgun_crab@lemmy.world
      link
      fedilink
      English
      arrow-up
      10
      ·
      1 year ago

      Comment edits are the best version control system

      • Rikudou_SageA
        link
        fedilink
        arrow-up
        5
        ·
        1 year ago

        I agree! Added new commit to my comment.

  • marcos@lemmy.world
    link
    fedilink
    arrow-up
    54
    ·
    1 year ago

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

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

    • Captain Janeway@lemmy.world
      link
      fedilink
      arrow-up
      46
      ·
      1 year ago

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

      • taaz@biglemmowski.win
        link
        fedilink
        English
        arrow-up
        40
        ·
        1 year ago

        pretty sure that has to be against their TOS

        /s

        • mormegil@programming.dev
          link
          fedilink
          arrow-up
          3
          ·
          1 year ago

          That’s against the terms of math :-)

    • Aa!@lemmy.world
      link
      fedilink
      arrow-up
      19
      ·
      1 year ago

      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

    • fckreddit@lemmy.ml
      link
      fedilink
      arrow-up
      6
      ·
      1 year ago

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

      • marcos@lemmy.world
        link
        fedilink
        arrow-up
        12
        ·
        1 year ago

        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!

  • jubilationtcornpone@sh.itjust.works
    link
    fedilink
    English
    arrow-up
    38
    arrow-down
    1
    ·
    1 year ago

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

    • jol@discuss.tchncs.de
      link
      fedilink
      arrow-up
      32
      ·
      1 year ago

      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.

  • rem26_art@kbin.social
    link
    fedilink
    arrow-up
    28
    ·
    1 year ago

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

  • ryry1985@lemmy.world
    link
    fedilink
    arrow-up
    23
    ·
    1 year ago

    I love that it works and the ads are pretty good.

  • eluvatar@programming.dev
    link
    fedilink
    arrow-up
    16
    ·
    edit-2
    1 year ago

    The errors are great https://api.isevenapi.xyz/api/iseven/1.5

    ~~Sadly it’s not always accurate https://api.isevenapi.xyz/api/iseven/0~~ Edit: nevermind I’m an idiot

    It’s also greatly lacking in number support https://api.isevenapi.xyz/api/iseven/one

    • xmunk@sh.itjust.works
      link
      fedilink
      arrow-up
      11
      ·
      1 year ago

      Is even states that it only returns true for even, passing in an odd number is technically unsupported.

    • huf [he/him]@hexbear.net
      link
      fedilink
      English
      arrow-up
      2
      ·
      1 year ago

      zero is even, so i dont see how that one’s wrong

      • eluvatar@programming.dev
        link
        fedilink
        arrow-up
        2
        ·
        1 year ago

        Oh you’re right, I’m not sure what I was Ln thinking

  • CannotSleep420@lemmygrad.ml
    link
    fedilink
    English
    arrow-up
    10
    ·
    1 year ago

    What the fuck is a modulo? Is it some kind of npm package?

    • lud@lemm.ee
      link
      fedilink
      arrow-up
      8
      ·
      1 year ago

      Yes

      • gen/Eric@iusearchlinux.fyi
        link
        fedilink
        arrow-up
        3
        ·
        edit-2
        1 year ago

        Just Monika Modulo

      • 56!@lemmy.ml
        link
        fedilink
        arrow-up
        1
        ·
        1 year ago

        return (n % d + d) % d;

        ?

  • megaman@discuss.tchncs.de
    link
    fedilink
    arrow-up
    6
    ·
    1 year ago

    Funny as hell

  • morrowind@lemmy.ml
    link
    fedilink
    arrow-up
    1
    ·
    1 year ago

    I resent that there is a ruby developer included in there. isEven is not idiomatic naming. You should be using #even? from the standard library

    • fckreddit@lemmy.ml
      link
      fedilink
      arrow-up
      4
      ·
      1 year ago

      Sorry sir, most JS developers don’t use standard library functions. We just use npm packages wherever possible.

Programmer Humor@programming.dev

programmer_humor@programming.dev

Subscribe from Remote Instance

Create a post
You are not logged in. However you can subscribe from another Fediverse account, for example Lemmy or Mastodon. To do this, paste the following into the search field of your instance: !programmer_humor@programming.dev

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
Visibility: Public
globe

This community can be federated to other instances and be posted/commented in by their users.

  • 705 users / day
  • 4.69K users / week
  • 8.84K users / month
  • 17.9K users / 6 months
  • 96 local subscribers
  • 23.2K subscribers
  • 1.39K Posts
  • 51.1K Comments
  • Modlog
  • mods:
  • Feyter@programming.dev
  • adr1an@programming.dev
  • BurningTurtle@programming.dev
  • Pierre-Yves Lapersonne@programming.dev
  • BE: 0.19.11
  • Modlog
  • Instances
  • Docs
  • Code
  • join-lemmy.org