NekuSoul-Lemmy
  • Communities
  • Create Post
  • heart
    Support Lemmy
  • search
    Search
  • Login
  • Sign Up
Destide@feddit.uk to Programmer Humor@lemmy.mlEnglish · 21 hours ago

Infallible Code

lemmy.ml

message-square
129
fedilink
366

Infallible Code

lemmy.ml

Destide@feddit.uk to Programmer Humor@lemmy.mlEnglish · 21 hours ago
message-square
129
fedilink
alert-triangle
You must log in or register to comment.
  • Drunk & Root@sh.itjust.works
    link
    fedilink
    arrow-up
    1
    ·
    3 minutes ago

    this is like the making chess one

  • JackbyDev@programming.dev
    link
    fedilink
    English
    arrow-up
    2
    ·
    33 minutes ago

    This is why this code is good. Opens MS paint. When I worked at Blizzard-

  • Valmond@lemmy.world
    link
    fedilink
    arrow-up
    1
    ·
    17 minutes ago

    private?

  • kreskin@lemmy.world
    link
    fedilink
    arrow-up
    1
    ·
    39 minutes ago

    no unit tests huh.

    /s

  • sik0fewl@lemmy.ca
    link
    fedilink
    arrow-up
    5
    ·
    5 hours ago

    This code would run a lot faster as a hash table look up.

    • Valmond@lemmy.world
      link
      fedilink
      arrow-up
      1
      ·
      16 minutes ago

      In a Juliana tree, or a dictionary tree if you want. For speed.

    • PieMePlenty@lemmy.world
      link
      fedilink
      arrow-up
      1
      ·
      46 minutes ago

      I agree. Just need a table of even numbers. Oh and a table of odd numbers, of course, else you cant return the false… duh.

  • redxef@feddit.org
    link
    fedilink
    arrow-up
    21
    ·
    10 hours ago
    def is_even(n: int) -> bool:
        if n < 0:
            return is_even(-n)
        r = True
        for _ in range(n):
            r = not r
        return r
    
    • vandsjov@feddit.dk
      link
      fedilink
      arrow-up
      1
      ·
      59 minutes ago

      No, no, I would convert the number to a string and just check the last char to see if it was even or not.

  • Patches@ttrpg.network
    link
    fedilink
    arrow-up
    9
    ·
    9 hours ago

    Y’all laugh but this man has amazing code coverage numbers.

  • thatradomguy@lemmy.world
    link
    fedilink
    arrow-up
    5
    ·
    7 hours ago

    Can you imagine being a TA and having to grade somebody’s hw and you get this first thing? lmao

  • kamen@lemmy.world
    link
    fedilink
    arrow-up
    18
    ·
    11 hours ago

    Plot twist: they used a script to generate that code.

  • Clbull@lemmy.world
    link
    fedilink
    arrow-up
    14
    ·
    11 hours ago

    This is YandereDev levels of bad.

    • lime!@feddit.nu
      link
      fedilink
      English
      arrow-up
      2
      ·
      7 hours ago

      this is yanderedev.

      • Clbull@lemmy.world
        link
        fedilink
        arrow-up
        2
        ·
        6 hours ago

        Nah, this is yanderedev

        • lime!@feddit.nu
          link
          fedilink
          English
          arrow-up
          1
          ·
          4 minutes ago

          no the code is

  • segfault11 [any]@hexbear.net
    link
    fedilink
    English
    arrow-up
    15
    ·
    11 hours ago

    pro hacker tip: you can optimize this by using “num” for the variable name instead of “number”

    • Patches@ttrpg.network
      link
      fedilink
      arrow-up
      2
      ·
      9 hours ago

      I prefer the cryptic each variable gets a single letter of the alphabet.

  • xorollo@leminal.space
    link
    fedilink
    arrow-up
    5
    arrow-down
    1
    ·
    8 hours ago

    This joke was not written by the dude pictured. The author wrote a book of funny code jokes.

  • Euphoma@lemmy.ml
    link
    fedilink
    English
    arrow-up
    19
    ·
    12 hours 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

    • xthexder@l.sw0.com
      link
      fedilink
      arrow-up
      3
      ·
      9 hours ago

      Not even else if? Damn, I guess we’re checking all the numbers every time then. This is what peak performance looks like

      • lime!@feddit.nu
        link
        fedilink
        English
        arrow-up
        3
        ·
        7 hours ago

        O(1) means worst and best case performance are the same.

  • XPost3000@lemmy.ml
    link
    fedilink
    arrow-up
    13
    ·
    11 hours ago

    You don’t get it, it runs on a smart fridge so there’s no reason to change it

    • theherk@lemmy.world
      link
      fedilink
      arrow-up
      3
      ·
      10 hours ago
      • a smart fridge’s monitor
  • last_philosopher@lemmy.world
    link
    fedilink
    arrow-up
    2
    ·
    8 hours ago

    To be fair, the question is “Write a function that simultaneously determines if the number is even and works as a timer”

    • JackbyDev@programming.dev
      link
      fedilink
      English
      arrow-up
      1
      ·
      31 minutes ago

      sleepSort meets sleepIsEven

Programmer Humor@lemmy.ml

programmerhumor@lemmy.ml

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: !programmerhumor@lemmy.ml

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

  • Posts must be relevant to programming, programmers, or computer science.
  • No NSFW content.
  • Jokes must be in good taste. No hate speech, bigotry, etc.
Visibility: Public
globe

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

  • 731 users / day
  • 520 users / week
  • 2.37K users / month
  • 8.71K users / 6 months
  • 1 local subscriber
  • 37.2K subscribers
  • 1.2K Posts
  • 22K Comments
  • Modlog
  • mods:
  • AgreeableLandscape@lemmy.ml
  • cat_programmer@lemmy.ml
  • BE: 0.19.8
  • Modlog
  • Instances
  • Docs
  • Code
  • join-lemmy.org