UmU
  • Communities
  • Create Post
  • heart
    Support Lemmy
  • search
    Search
  • Login
  • Sign Up
Destide@feddit.uk to Programmer Humor@lemmy.mlEnglish · 1 day ago

Infallible Code

lemmy.ml

message-square
146
fedilink
423

Infallible Code

lemmy.ml

Destide@feddit.uk to Programmer Humor@lemmy.mlEnglish · 1 day ago
message-square
146
fedilink
alert-triangle
You must log in or register to comment.
  • keepcarrot [she/her]@hexbear.net
    link
    fedilink
    English
    arrow-up
    2
    ·
    54 minutes ago

    I want to assess coders by lines written! The more the better!

  • JackbyDev@programming.dev
    link
    fedilink
    English
    arrow-up
    19
    ·
    6 hours ago

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

    • benjaminb@discuss.tchncs.de
      link
      fedilink
      English
      arrow-up
      1
      ·
      45 minutes ago

      And he has Whatever+ years of experience in the game industry…

  • Treczoks@lemmy.world
    link
    fedilink
    arrow-up
    3
    ·
    5 hours ago

    Good if you are rated by an AI that pays for LOCs.

  • kreskin@lemmy.world
    link
    fedilink
    arrow-up
    5
    ·
    6 hours ago

    no unit tests huh.

    /s

  • 6stringringer@lemmy.zip
    link
    fedilink
    arrow-up
    2
    ·
    4 hours ago

    Thanks to goodness, finally. A (giggle & snort) solid algorithm. There ya’s go set yer clocks & go get a haircut.

  • Drunk & Root@sh.itjust.works
    link
    fedilink
    arrow-up
    1
    ·
    5 hours ago

    this is like the making chess one

  • Valmond@lemmy.world
    link
    fedilink
    arrow-up
    1
    ·
    5 hours ago

    private?

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

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

    • Valmond@lemmy.world
      link
      fedilink
      arrow-up
      3
      ·
      5 hours ago

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

    • PieMePlenty@lemmy.world
      link
      fedilink
      arrow-up
      4
      ·
      6 hours 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
    28
    ·
    15 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
    
    • dragonlobster@programming.dev
      link
      fedilink
      arrow-up
      1
      ·
      14 minutes ago

      He loves me, he loves me not

    • vandsjov@feddit.dk
      link
      fedilink
      arrow-up
      1
      ·
      6 hours 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
    12
    ·
    14 hours ago

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

  • Clbull@lemmy.world
    link
    fedilink
    arrow-up
    18
    ·
    16 hours ago

    This is YandereDev levels of bad.

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

      this is yanderedev.

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

        Nah, this is yanderedev

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

          no the code is

  • thatradomguy@lemmy.world
    link
    fedilink
    arrow-up
    6
    ·
    13 hours ago

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

  • segfault11 [any]@hexbear.net
    link
    fedilink
    English
    arrow-up
    18
    ·
    16 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
      4
      ·
      14 hours ago

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

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

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

  • Euphoma@lemmy.ml
    link
    fedilink
    English
    arrow-up
    20
    ·
    17 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
      5
      ·
      14 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
        5
        ·
        12 hours ago

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

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: [email protected]

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.

  • 841 users / day
  • 1.42K users / week
  • 3K users / month
  • 9.53K users / 6 months
  • 2 local subscribers
  • 37.2K subscribers
  • 1.41K Posts
  • 22.1K Comments
  • Modlog
  • mods:
  • AgreeableLandscape@lemmy.ml
  • cat_programmer@lemmy.ml
  • BE: 0.19.9
  • Modlog
  • Instances
  • Docs
  • Code
  • join-lemmy.org