Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo

agnos.is Forums

  1. Home
  2. Programmer Humor
  3. Infallible Code

Infallible Code

Scheduled Pinned Locked Moved Programmer Humor
programmerhumor
52 Posts 40 Posters 3 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K [email protected]

    Better/fastest approch would be to check the last bit of the int and return the result.
    Second use modulo.

    This? Dev should burn in hell.
    Who created this?

    T This user is from outside of this forum
    T This user is from outside of this forum
    [email protected]
    wrote on last edited by [email protected]
    #21

    or another stupid, but viable way to do it,

    if number = 0:

    return true

    runloop = true

    while runloop:

    if number > 0:

    number -= 2

    else:

    number += 2

    if number = 1:

    return false

    runloop = false

    if number = 2:

    return true

    runloop = false

    still very shitty amature coding, doesn't depend on modulos, or anything that I can think of that some languages might lack an equivelant of.

    1 Reply Last reply
    2
    • S [email protected]

      After working at blizzard for 51 years, I finally found an elegant solution by using the power of recursion

      private bool IsEven(int number){
        if (number > 1) return IsEven(number - 2);
        if (number == 0) return true;
        if (number == 1) return false;
      }
      
      E This user is from outside of this forum
      E This user is from outside of this forum
      [email protected]
      wrote on last edited by
      #22
      assert IsEven(-2);
      
      lambda@programming.devL 1 Reply Last reply
      37
      • S [email protected]

        After working at blizzard for 51 years, I finally found an elegant solution by using the power of recursion

        private bool IsEven(int number){
          if (number > 1) return IsEven(number - 2);
          if (number == 0) return true;
          if (number == 1) return false;
        }
        
        E This user is from outside of this forum
        E This user is from outside of this forum
        [email protected]
        wrote on last edited by
        #23

        I removed the tail recursion for you:

        private book IsEven(int number) {
            if(number > 1) return IsEven(number - 2) == true;
            if(number == 0) return true; 
            if(number == 2) return false;
        }
        
        U F 2 Replies Last reply
        13
        • E [email protected]

          I removed the tail recursion for you:

          private book IsEven(int number) {
              if(number > 1) return IsEven(number - 2) == true;
              if(number == 0) return true; 
              if(number == 2) return false;
          }
          
          U This user is from outside of this forum
          U This user is from outside of this forum
          [email protected]
          wrote on last edited by
          #24

          I didn't get this.

          Why return book? Does that have some Blizzard reference?
          And why would number == 2 โ‡’ return false? This is a function for getting true when the number is even, right?

          E 1 Reply Last reply
          4
          • cm0002@lemmy.worldC [email protected]
            This post did not contain any content.
            _cnt0@sh.itjust.works_ This user is from outside of this forum
            _cnt0@sh.itjust.works_ This user is from outside of this forum
            [email protected]
            wrote on last edited by
            #25

            Not to take from all the funny answers ... but

            bool IsEven(int i) => (i & 1) != 1;
            

            (C#)

            _cnt0@sh.itjust.works_ 1 Reply Last reply
            2
            • U [email protected]

              I didn't get this.

              Why return book? Does that have some Blizzard reference?
              And why would number == 2 โ‡’ return false? This is a function for getting true when the number is even, right?

              E This user is from outside of this forum
              E This user is from outside of this forum
              [email protected]
              wrote on last edited by [email protected]
              #26

              Haha, you're right. I've now learned two things:

              1. I should not write code on a mobile
              2. I should not become a proof reader

              At the end of the day i just wanted the function to be worse, by causing stack overflows

              1 Reply Last reply
              12
              • _cnt0@sh.itjust.works_ [email protected]

                Not to take from all the funny answers ... but

                bool IsEven(int i) => (i & 1) != 1;
                

                (C#)

                _cnt0@sh.itjust.works_ This user is from outside of this forum
                _cnt0@sh.itjust.works_ This user is from outside of this forum
                [email protected]
                wrote on last edited by
                #27

                Though, obviously I had to come up with some ridiculous solutions:

                bool IsEven(int i) => ((Func<string, bool>)(s => s[^1] == 48))($"{i:B}");
                

                This one works without conditionals ๐Ÿ™‚

                bool IsEven(int i)
                {
                    try
                    {
                        int _ = (i & 1) / (i & 1);
                    }
                    catch (Exception)
                    {
                        return true;
                    }
                
                    return false;
                }
                
                L 1 Reply Last reply
                0
                • cm0002@lemmy.worldC [email protected]
                  This post did not contain any content.
                  typewar@infosec.pubT This user is from outside of this forum
                  typewar@infosec.pubT This user is from outside of this forum
                  [email protected]
                  wrote on last edited by
                  #28

                  Lol the amount of bullying this guy is getting lately. I've seen similar spins and bends that looks somewhat legit, making people believe he suck at coding

                  1 Reply Last reply
                  8
                  • cm0002@lemmy.worldC [email protected]
                    This post did not contain any content.
                    tux0r@feddit.orgT This user is from outside of this forum
                    tux0r@feddit.orgT This user is from outside of this forum
                    [email protected]
                    wrote on last edited by
                    #29

                    Then again, Duffโ€™s Device works rather similarly.

                    1 Reply Last reply
                    4
                    • xxce2aab@feddit.dkX [email protected]

                      Pah, mathematicians and their generally applicable pure approach to solutions and fancy modulus operations, who needs 'em? Computing is applied and we always work with well-defined finite precision. Granted, writing the boilerplate for all possible 64 bit integers is a bit laborious, but we're programmers! That's what code generation is for.

                      J This user is from outside of this forum
                      J This user is from outside of this forum
                      [email protected]
                      wrote on last edited by
                      #30

                      Granted, writing the boilerplate for all possible 64 bit integers is a bit laborious,

                      I've been trying to figure out roughly how many lines of code that would equal out to but I've run out of fingers.

                      xxce2aab@feddit.dkX 1 Reply Last reply
                      1
                      • M [email protected]

                        I worked at Blizzard. I worked at Blizzard. I worked at Blizzard.

                        L This user is from outside of this forum
                        L This user is from outside of this forum
                        [email protected]
                        wrote on last edited by
                        #31

                        Yeah, but did your dad work at Blizzard??

                        M 1 Reply Last reply
                        13
                        • M [email protected]

                          At least this madness is isolated to this function. It can easily be fixed.

                          Pirateโ€™s code is just cluttered with magic numbers everywhere. Hard coded numbers that are referring to a big โ€story arrayโ€, or characters. Itโ€™s just a giant web of complexity. The only fix is to start from scratch.

                          L This user is from outside of this forum
                          L This user is from outside of this forum
                          [email protected]
                          wrote on last edited by
                          #32

                          It's simple. The only problem is that your code sucks!

                          1 Reply Last reply
                          3
                          • _cnt0@sh.itjust.works_ [email protected]

                            Though, obviously I had to come up with some ridiculous solutions:

                            bool IsEven(int i) => ((Func<string, bool>)(s => s[^1] == 48))($"{i:B}");
                            

                            This one works without conditionals ๐Ÿ™‚

                            bool IsEven(int i)
                            {
                                try
                                {
                                    int _ = (i & 1) / (i & 1);
                                }
                                catch (Exception)
                                {
                                    return true;
                                }
                            
                                return false;
                            }
                            
                            L This user is from outside of this forum
                            L This user is from outside of this forum
                            [email protected]
                            wrote on last edited by
                            #33

                            s[^1]

                            Ohh wow, I've been learning it casually for years, and I didn't know that existed in C#. I guess I should go back and hit the books some more.

                            1 Reply Last reply
                            0
                            • P This user is from outside of this forum
                              P This user is from outside of this forum
                              [email protected]
                              wrote on last edited by
                              #34

                              If small numbers are much more frequent, it's better to return early. Really, you should gather statistics about the numbers the function is called with, and put the most frequent ones at the top.

                              1 Reply Last reply
                              2
                              • themoonisacheese@sh.itjust.worksT [email protected]

                                Obligatory: https://codegolf.stackexchange.com/q/275739/88192

                                L This user is from outside of this forum
                                L This user is from outside of this forum
                                [email protected]
                                wrote on last edited by
                                #35

                                The fuck is that

                                themoonisacheese@sh.itjust.worksT 1 Reply Last reply
                                1
                                • J [email protected]

                                  Granted, writing the boilerplate for all possible 64 bit integers is a bit laborious,

                                  I've been trying to figure out roughly how many lines of code that would equal out to but I've run out of fingers.

                                  xxce2aab@feddit.dkX This user is from outside of this forum
                                  xxce2aab@feddit.dkX This user is from outside of this forum
                                  [email protected]
                                  wrote on last edited by
                                  #36

                                  Ah, common issue. When that happens, you just start using your toes.

                                  1 Reply Last reply
                                  2
                                  • L [email protected]

                                    Yeah, but did your dad work at Blizzard??

                                    M This user is from outside of this forum
                                    M This user is from outside of this forum
                                    [email protected]
                                    wrote on last edited by
                                    #37

                                    Iโ€™m the first ever second generation Blizzard employee!

                                    S 1 Reply Last reply
                                    8
                                    • W [email protected]

                                      Definitely a vibe.

                                      V This user is from outside of this forum
                                      V This user is from outside of this forum
                                      [email protected]
                                      wrote on last edited by [email protected]
                                      #38

                                      The only way I could see that happening is if enough people poisoned the data to do this

                                      1 Reply Last reply
                                      1
                                      • E [email protected]
                                        assert IsEven(-2);
                                        
                                        lambda@programming.devL This user is from outside of this forum
                                        lambda@programming.devL This user is from outside of this forum
                                        [email protected]
                                        wrote on last edited by
                                        #39

                                        Now see, you need the other method. IsNegativeEven()

                                        S 1 Reply Last reply
                                        12
                                        • cm0002@lemmy.worldC [email protected]
                                          This post did not contain any content.
                                          B This user is from outside of this forum
                                          B This user is from outside of this forum
                                          [email protected]
                                          wrote on last edited by
                                          #40

                                          Even plus even equals even.

                                          Odd plus odd equals even.

                                          Only odd plus even makes an odd.

                                          Are there twice as many even numbers as there are odd numbers?

                                          witchfire@lemmy.worldW 1 Reply Last reply
                                          11
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups