okr765
  • Communities
  • Create Post
  • Create Community
  • 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
133
fedilink
408

Infallible Code

lemmy.ml

Destide@feddit.uk to Programmer Humor@lemmy.mlEnglish · 1 day ago
message-square
133
fedilink
alert-triangle
You must log in or register to comment.
  • Kuma@lemmy.world
    link
    fedilink
    arrow-up
    5
    arrow-down
    1
    ·
    2 hours ago

    I am more amazed that he didn’t stop at 10 and think “damn this is tiresome isn’t there a one liner i could do?”. I want to know how far he went. His stubbornness is amazing but also scary. I haven’t seen this kind of code since back in school lol lol lol

  • WraithGear@lemmy.world
    link
    fedilink
    English
    arrow-up
    1
    arrow-down
    1
    ·
    edit-2
    52 minutes ago

    Would this be a case of modulo saving the day?

    Like: If Number modulo 2 = 0, true

    This has to be taken out of context

  • JackbyDev@programming.dev
    link
    fedilink
    English
    arrow-up
    31
    ·
    8 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
      5
      ·
      3 hours ago

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

      • onlooker@lemmy.ml
        link
        fedilink
        arrow-up
        2
        ·
        2 hours ago

        Which sounds impressive until you realize a janitor who worked there for the same amount of time could claim the same.

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

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

  • kreskin@lemmy.world
    link
    fedilink
    arrow-up
    6
    arrow-down
    1
    ·
    8 hours ago

    no unit tests huh.

    /s

  • 6stringringer@lemmy.zip
    link
    fedilink
    arrow-up
    2
    ·
    7 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
    ·
    8 hours ago

    this is like the making chess one

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

    private?

  • sik0fewl@lemmy.ca
    link
    fedilink
    arrow-up
    9
    arrow-down
    1
    ·
    13 hours ago

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

    • Valmond@lemmy.world
      link
      fedilink
      arrow-up
      4
      ·
      8 hours ago

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

    • PieMePlenty@lemmy.world
      link
      fedilink
      arrow-up
      5
      ·
      9 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
    32
    ·
    18 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
      2
      ·
      3 hours ago

      He loves me, he loves me not

    • vandsjov@feddit.dk
      link
      fedilink
      arrow-up
      1
      ·
      9 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
    13
    ·
    16 hours ago

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

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

    This is YandereDev levels of bad.

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

      this is yanderedev.

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

        Nah, this is yanderedev

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

          no the code is

  • thatradomguy@lemmy.world
    link
    fedilink
    arrow-up
    7
    ·
    15 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
    19
    ·
    19 hours ago

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

  • Euphoma@lemmy.ml
    link
    fedilink
    English
    arrow-up
    19
    ·
    20 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
      ·
      17 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
        6
        ·
        15 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: !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.

  • 710 users / day
  • 1.41K users / week
  • 2.99K users / month
  • 9.44K users / 6 months
  • 1 local subscriber
  • 37.2K subscribers
  • 1.28K Posts
  • 18K Comments
  • Modlog
  • mods:
  • AgreeableLandscape@lemmy.ml
  • cat_programmer@lemmy.ml
  • BE: 0.19.9
  • Modlog
  • Instances
  • Docs
  • Code
  • join-lemmy.org