The Daily WTF: Curious Perversions in Information Technology
Welcome to TDWTF Forums Sign in | Join | Help
in Search

You didn't say we couldn't...

Last post 05-17-2007 6:29 PM by Taejo. 5 replies.
Page 1 of 1 (6 items)
Sort Posts: Previous Next
  • 05-08-2007 2:50 PM

    You didn't say we couldn't...

    Alright, I doubt this would actually fly, but:

    // TODO - No time to finish real parser, just check for the test cases to buy some time...
    if (szInput == "1 + 1 =") {
      display("2");
    } else if (szInput == "2 - 1 =") {
      ...
    }



     

  • 05-08-2007 2:59 PM In reply to

    Re: You didn't say we couldn't...

    I certainly hope we can, since my solution works a lot like this one.  A bit more creative in its implementation, though...
  • 05-08-2007 5:15 PM In reply to

    Re: You didn't say we couldn't...

    As long it passes test cases, you can do everything you want inside your WTF code :D
  • 05-08-2007 8:21 PM In reply to

    • SamP
    • Not Ranked
    • Joined on 05-05-2007
    • Posts 25

    Re: You didn't say we couldn't...

    To be able to calculate 6-digit numbers, having hundreds of millions of line of code would be impractical even for a WTF application, and probably would fail the load and execution time constraints, as well as run out of system memory.

    A more practical way is to make a case statement dealing with every possible binary operation of two single-digit numbers. When accepting multi-digit numbers, break them down into single-digits and work on each digit, carrying overflow over.

    Pretty much exactly the way elementary school math works. But you can slap on top all kinds of "creative" twists, such as using recursive functions, remembering that multiplication is just fancy addition (same with subtraction).

    Another wise idea: for division, you can implement a single function 1/X which returns the inverse of a given number (and lots of rooms for WTFs in it too), and then treat the result as a multiplication operand. (so dividing 12 by 7 would be multiplying 12 by 1/7)

  • 05-09-2007 2:01 PM In reply to

    Re: You didn't say we couldn't...

    darkstar949:

    Alright, I doubt this would actually fly, but:

    // TODO - No time to finish real parser, just check for the test cases to buy some time...
    if (szInput == "1 + 1 =") {
      display("2");
    } else if (szInput == "2 - 1 =") {
      ...
    }

    My second entry is going to do exactly that, only in a much, much more enterprisey way.

  • 05-17-2007 6:29 PM In reply to

    • Taejo
    • Not Ranked
    • Joined on 05-14-2007
    • Posts 5

    Re: You didn't say we couldn't...

    SamP:

    Another wise idea: for division, you can implement a single function 1/X which returns the inverse of a given number (and lots of rooms for WTFs in it too), and then treat the result as a multiplication operand. (so dividing 12 by 7 would be multiplying 12 by 1/7)

     Indeed you can (and there is). I use Simpson's Rule to calculate the integral of 1/x, which is log(x), and then use the central difference approximation to calculate the derivative of log(x).
     

Page 1 of 1 (6 items)
Powered by Community Server (Non-Commercial Edition), by Telligent Systems