• QuazarOmega@lemy.lol
    link
    fedilink
    arrow-up
    2
    ·
    6 months ago

    No, no, you should group the return false lines together 😤😤

    if (number == 1) return false;
    else if (number == 3) return false;
    else if (number == 5) return false;
    //...
    else if (number == 2) return true;
    else if (number == 4) return true;
    //...
    
  • Euphoma@lemmy.ml
    link
    fedilink
    English
    arrow-up
    2
    ·
    6 months ago
    def even(n: int) -> bool:
        code = ""
        for i in range(0, n+1, 2):
            code += f"if {n} == {i}:\n out = True\n"
            j = i+1
            code += f"if {n} == {j}:\n out = False\n"
        local_vars = {}
        exec(code, {}, local_vars)
        return local_vars["out"]
    

    scalable version

  • kryptonianCodeMonkey@lemmy.world
    link
    fedilink
    arrow-up
    1
    ·
    edit-2
    6 months ago
    def is_even(num):
        if num == 1:
            return False
        if num == 2:
            return True
        raise ValueError(f'Value of {num} out of range. Literally impossible to tell if it is even.')
  • FunkyStuff [he/him]@hexbear.net
    link
    fedilink
    English
    arrow-up
    1
    ·
    edit-2
    6 months ago

    Throwback to when someone shared the OG version of this meme to my uni chat, I replied with "Oh you can simply do

    def is_even(n: int) -> boolean:
        if n > 0 return not is_even(n - 1)
        elif n < 0 return not is_even(n + 1)
        else return True
    

    And instead of laughing at the joke the TA in the chat said “When you start getting internships you’ll do n % 2” like I was being serious.

  • AlyxMS [he/him]@hexbear.net
    link
    fedilink
    English
    arrow-up
    1
    ·
    6 months ago

    What you do is use a for loop to generate a million lines for you, then paste it in. Writing it manually is moronic. You can easily make it support numbers above 1,000,000 too this way, talking about scalable

    • balsoft@lemmy.ml
      link
      fedilink
      arrow-up
      0
      ·
      6 months ago

      No, silly. You ask chatgpt to write (steal) a loop that would generate all those lines. Haven’t you heard about meta-vibe template-programming?

      • AlyxMS [he/him]@hexbear.net
        link
        fedilink
        English
        arrow-up
        0
        ·
        6 months ago

        I once saw someone unironically sharing their new trick of “if you need to write a bunch of really similar lines just with different numbers, chatGPT does it really well”.

        Kind of blew my mind (and everyone else that saw the thread)

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

    pff, i aint reading all that, lemme optimize it:

    private bool isEven(int number) {
        return rand() < 0.5;
    }
    
    • ImplyingImplications@lemmy.ca
      link
      fedilink
      arrow-up
      2
      ·
      6 months ago

      YanDev is a literal pedophile. It’s honestly mind boggling people care more about a guy who won’t sign a petition on preserving video games than pedophiles and bigots. I don’t get the hate.