34 votes

4 billion if statements

6 comments

  1. [5]
    SloMoMonday
    (edited )
    Link
    There's something awe inspiring about high-effort bad design. It's like a window into a world where we were one breakthrough away from a truly elegant solution but just have to make do with a...

    There's something awe inspiring about high-effort bad design.

    It's like a window into a world where we were one breakthrough away from a truly elegant solution but just have to make do with a cumbersome mess.

    So please take a moment to imagine a world where an even/odd calculation could require a 40gb program that runs a 10 second computation and has a hard limit of in the billions (because there's no calculations that would ever need more then that) .

    18 votes
    1. [2]
      krellor
      Link Parent
      Just write a script to write more ifs when you need more than 4 billion. Or a just-in-time compiled program triggered by a script that accepts the max value writes the program and then executes...

      Just write a script to write more ifs when you need more than 4 billion. Or a just-in-time compiled program triggered by a script that accepts the max value writes the program and then executes it. 😂

      Of course, the pseudocode has to be as terrible as possible for the task.

      bool even = 0;
      print("if(num == 0) { print(\"even\") ;}\r\n")
      for(i=1;i<max;i++) {
          if(even) {
              print("elif(num == {0}) { print(\"even\"); }\r\n", num);
              even = 0;
          elif {
              print("elif(num == {0}) { print(\"odd\"); }\r\n", num);
              even = 1;
          }
      }
      
      if(even) {
          print("elif(num == {0}) { print(\"even\"); }", max);
          even = 0;
      elif {
          print("elif(num == {0}) { print(\"odd\"); }", max);
          even = 1;
      }
      
      9 votes
      1. ebonGavia
        Link Parent
        Couldn't we unroll those for loops for even more performance? Bet it would be wicked fast

        Couldn't we unroll those for loops for even more performance? Bet it would be wicked fast

        6 votes
    2. Interesting
      Link Parent
      They certainly are fun. Another favorite of mine (though a bit more practical) is a guy who fixed the Atari ET game http://www.neocomputer.org/projects/et/

      They certainly are fun. Another favorite of mine (though a bit more practical) is a guy who fixed the Atari ET game http://www.neocomputer.org/projects/et/

      4 votes
    3. Chinpokomon
      Link Parent
      I think there are better ways. Even numbers are those which are evenly divisible by 2. Odd numbers are those which are not even. Therefore, Start at 0 Add 2 Check, is this your number? Goto 2 When...

      I think there are better ways.

      1. Even numbers are those which are evenly divisible by 2.
      2. Odd numbers are those which are not even.

      Therefore,

      1. Start at 0
      2. Add 2
      3. Check, is this your number?
      4. Goto 2

      When you find your number, you will know it is Even.

      I know way you're thinking. And you're right, this is only covering half of the numbers. So I've also worked on a fix. It will run about half as fast, but O() time is technically the same. So yay!

      1. Assign the value of 0 to the variables A and B
      2. Add 2 to A
      3. Check, is this your number?
      4. Subtract 2 from B
      5. Check, is this your number?
      6. Goto 2
      2 votes
  2. akselmo
    Link
    I hate that i love this

    I hate that i love this

    4 votes