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.
  • lambda@programming.devL [email protected]

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

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

    We can avoid expensive branches (gasp) by using some bitwise arithmetic to achieve the so-called "absolute value", an advanced hacker technique I learnt at Blizzard. Also unlike c, c# is not enlightened enough to understand that my code is perfect so it complains about "not all code paths returning a value".

    private bool IsEven(int number)
    {
        number *= 1 - 2*(int)(((uint)number & 2147483648) >> 31);
        if (number > 1) return IsEven(number - 2);
        if (number == 0) return true;
        if (number == 1) return false;
        throw new Exception();
    }
    
    U 1 Reply Last reply
    8
    • B [email protected]

      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 This user is from outside of this forum
      witchfire@lemmy.worldW This user is from outside of this forum
      [email protected]
      wrote on last edited by
      #43

      Even plus even

      Odd plus odd

      Even plus odd

      Odd plus even

      N 1 Reply Last reply
      6
      • witchfire@lemmy.worldW [email protected]

        Even plus even

        Odd plus odd

        Even plus odd

        Odd plus even

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

        Are we working with a non-abelian group? Other wise this would work.

        1 Reply Last reply
        0
        • M [email protected]

          I’m the first ever second generation Blizzard employee!

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

          This is such an unhinged thing to say, it had me rolling.

          1 Reply Last reply
          2
          • mossyfeathers@pawb.socialM [email protected]

            Did you know that he worked for Blizzard for seven years? Not only that, but he was Blizzard's first second-generation employee. He grew up in Blizzard. An extreme accomplishment to be certain. Thank you based and blizzpilled Pirate Software.

            I wonder if he was the one stealing the breast milk. After all, I've heard he can be really childish.

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

            The funniest thing about his blizzard obsession and the fact that his dad is like a first generation blizzard employee is such a weird glex these days.

            So, did you get to harass any women yourself, or did you get your dad watch doing it? Were you a high enough employee that they gave you the Bill Cosby room to rape someone?

            1 Reply Last reply
            1
            • 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;
              }
              
              F This user is from outside of this forum
              F This user is from outside of this forum
              [email protected]
              wrote on last edited by
              #47

              What'd be the result for IsEven(1)?

              E 1 Reply Last reply
              2
              • lefrog@discuss.tchncs.deL [email protected]

                This noob even forgot zero

                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
                #48

                That and all negative values

                0 1 Reply Last reply
                1
                • F [email protected]

                  What'd be the result for IsEven(1)?

                  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
                  #49

                  Stack overflow

                  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.

                    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
                    #50

                    You can generate the code with a simple macro.

                    1 Reply Last reply
                    1
                    • P [email protected]

                      That and all negative values

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

                      Patience guys, I'm sure they'll get to supporting zero and negative integers as soon as they finish all positive integers

                      1 Reply Last reply
                      0
                      • S [email protected]

                        We can avoid expensive branches (gasp) by using some bitwise arithmetic to achieve the so-called "absolute value", an advanced hacker technique I learnt at Blizzard. Also unlike c, c# is not enlightened enough to understand that my code is perfect so it complains about "not all code paths returning a value".

                        private bool IsEven(int number)
                        {
                            number *= 1 - 2*(int)(((uint)number & 2147483648) >> 31);
                            if (number > 1) return IsEven(number - 2);
                            if (number == 0) return true;
                            if (number == 1) return false;
                            throw new Exception();
                        }
                        
                        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
                        #52

                        Nice, now we just need another function to find odd numbers, cause not all numbers are even you know.

                        1 Reply Last reply
                        1
                        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