• FunkyStuff [he/him]@hexbear.net
    link
    fedilink
    English
    arrow-up
    1
    ·
    edit-2
    21 days 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.

  • Euphoma@lemmy.ml
    link
    fedilink
    English
    arrow-up
    1
    ·
    20 days 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

  • AlyxMS [he/him]@hexbear.net
    link
    fedilink
    English
    arrow-up
    1
    ·
    21 days 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
      ·
      20 days 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
        ·
        20 days 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
    ·
    21 days ago

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

    private bool isEven(int number) {
        return rand() < 0.5;
    }
    
  • 4am@lemmy.zip
    link
    fedilink
    arrow-up
    0
    ·
    21 days ago

    Fucking rent free. Jesus Christ you clowns, I almost want them to take away all your video games now

  • ferric_carcinization@lemmy.ml
    link
    fedilink
    English
    arrow-up
    0
    ·
    20 days ago

    I hope that the language’s ints are at most 32 bits. For 8 bits it could even be written by hand & the source code for a 32 bit version would only take up avg_line_len * 4GiB space for the source code of the function. But it might take a bit of time to compile a version that supports the full range of 64 or 128 bit ints.

    • Patches@ttrpg.network
      link
      fedilink
      arrow-up
      1
      ·
      edit-2
      20 days ago

      My mate, Paul, says all numbers after 700 repeat so we can stop there.

      We just give them different names so you think they’re going up.