About The Contest

The first ever Olympiad of Misguided Geeks contest at Worse Than Failure (or OMGWTF for short) is a new kind of programming contest. Readers are invited to be creative with devising a calculator with the craziest code they can write. One lucky and potentially insane winner will get either a brand new MacBook Pro or comparable Sony VAIO laptop.

Navigation

Advertisements

Entry #100101: The OOMGWTFFFC (Optimized Oh My God Worst Than Failure Four Function Calculator)

by Ronald Chen
Introduction
~~~~~~~~~~~~
I am a highly paid consultant, thus naturally I am a specialist in everything. However, for this simple four function calculator project, I will be calling upon my optimization geniusness. But enough about me, let's get paradigming.


Analysis
~~~~~~~~
After a thorough analysis of the specifications, I noticed that each operator in the four function calculator will take a finite amount of processing time. Typically these operations will take a few cycles, however using my optimization geniusness I have come up with a way to exceed all previously conceived performance expectations.

I will be applying a completely new and exciting technology called caching. Caching is simply a buffer holding future results. So for example, to apply caching to this project, instead of spending the large amount of cycles required to perform one of the four operators, a simple look up into the cache table will return the result desired. Since the result is already in the table, the result was achieved in 0 cycles! Given that actually applying the operators require a finite number of cycles, this is a performace increase of INFINITY!! How's that for your money!

However, since your target machine only has a pathetic 512 MB of ram, it is impossible to hold all the cached results in memory. Therefore, I will be creating a predictive caching system.


Design
~~~~~~
This predictive caching system will tie into the user interface to adaptively refine the values in the cache table. The calculator will use the user's input to predict the result. A short example is in order.

+--------------+-----------------------------------------------------------------------+
| User's input | Cache table |
+--------------+-----------------------------------------------------------------------+
| 1 | 1 + 1 = 2, 1 - 1 = 0, 1 * 1 = 1, 1 / 1 = 1, 1 + 2 = 3, 1 - 2 = -2 ... |
| 1 + | 1 + 1 = 2, 1 + 2 = 3, 1 + 3 = 4 ... |
| 1 + 1 | 1 + 1 = 2, 1 + 10 = 11, 1 + 11 = 12 ... |
| 1 + 1 = | Look up key '1 + 1 =', to find the result to be 2 |
+--------------+-----------------------------------------------------------------------+

If you noticed, the caching system found the result in the very first cache entry. Talk about a great prediction! That first result was never removed from the cache table, only the invalid ones were filtered out once it was known which operator the user picked and as the user entered more digits.

The cache table is populated using a separate thread using the time between user inputs. Therefore, the longer the time the user takes per click, the more complete the cache table is.


Conclusion
~~~~~~~~~~
My predictive caching system is absolutely brilliant. I am considing to patent it. As you use the implementation, you may notice that the cache hit is low. However, you must remember, since we have an infinite performance increase on cache hits, the average performance of this application is still infinite. Therefore even with 1 cache hit, this calculator is faster than any four function calculator in the universe.

During end-user testing, a small subset of unsatisfiable users complained that the calculator was slow. Given that the calculator has infinite performance, the only conclusion is that these users are crazy. I could also blame them for not allowing for an optimal ammount of time between clicks for the cache to properly fill. With some personal training (for a nominal fee), I can teach these users on how to use this calculator to maximize its potential.

Although you are my first client, given this incredible achievement of infinite performance, I think I will have to promote myself to ├╝berly paid consultant. Your invoice will reflect this promotion.

Download0 Comments