This is the seventh article in a twelve-part series that discusses the twelve finalists and their calculator submissions for the OMGWTF Programming Contest. The entries are being presented in the order submitted, and the winner will be announced on June 18, 2007.

Developing Completely Incorrect Solutions to Non-Existent Problems (The Customer Friendly System, Enterprise Rules Engine, etc) takes a lot of effort, a whole lot of smarts, and an almost infinite amount of misdirection. Each of these CIS2NEPs are borne from a very basic and theoretical concept, each starting with a single phrase: “wouldn’t it be nice if…” In the case of Entry #100206 (Charles Nadolski’s Rube Goldberg’s Calculator), it was “wouldn’t it be nice if we could use something than decimals?”

While a whole lot of other entries used a whole lot of unconventional methods, ranging from Roman Numerals in strings to N-Queen Solving State Machines, the Rube Goldberg’s Calculator used something that seemed so simple... so elegant… and yet so wrong. The basis for this CIS2NEP is fractions.

It makes some sense if you think about it. How meaningless is 0.109375 to you, or to any other human? Seven Sixty- fourths – now that’s something we can understand and quantify. It just makes sense. Why bother with all of those incomprehensible decimals.

Of course, Charles decision to simplify things with fractions meant that he’d have to implement fractional arithmetic algorithms. And the main problem with this is that such algorithms are notoriously slow. Do you remember how much of a pain it was to figure out the sum of eighteen twenty-thirds and four sevenths?

Thankfully, C++ allows for inline assembly code, which everyone knows is monumentally faster. Risking a slow calculator, Charles had no choice but to use it:

Fraction Fraction::operator +(Fraction &other)
    //Time to speed this puppy up. Adding fractions in C++ is just way too slow. Go go gadget INLINE!
    int nDenominator,nNumerator;
    int nThisNumerator = m_data.Numerator;
    int nOtherNumerator = other.m_data.Numerator;
    int nThisDenominator = m_data.Denominator;
    int nOtherDenominator = other.m_data.Denominator;
    short sThisSignage = m_data.Signage;
    short sOtherSignage = other.m_data.Signage;
        MOV eax,nThisDenominator
        IMUL eax,nOtherDenominator;
        MOV nDenominator,eax

        MOVD XMM0,nThisNumerator
        PSLLDQ XMM0,8
        PINSRW XMM0,nOtherNumerator,0
        PINSRW XMM0,nOtherNumerator+2,1
        MOVD XMM1,nOtherDenominator
        PSLLDQ XMM1,8
        PINSRW XMM1,nThisDenominator,0
        PINSRW XMM1,nThisDenominator+2,1


        MOVD ebx,XMM0
        PSRLDQ XMM0,8
        MOVD eax,XMM0

        CMP sThisSignage,Negative
        JE ThisNegative
        CMP sOtherSignage,Negative
        JE OtherNegative

        ADD eax,ebx
        MOV nNumerator,eax
        JMP ExitAdd
        SUB ebx,eax
        MOV nNumerator,ebx
        JMP ExitAdd
        SUB eax,ebx
        MOV nNumerator,eax
        JMP ExitAdd

    return Fraction(nNumerator, nDenominator);

One thing you may have noticed from the above code is that it’s clean and a member of the Fraction class. Like so many real-world CIS2NEPs, the code in this calculator is production quality, but yet, it’s not something that should ever have been produced.

To speed things along even further, The Rube Goldberg’s Calculator also makes use of an XML result cache. The schema for that is just as straightforward and unecessary:


What I find so disturbing about this solution is that it’s exactly the type of solution that I’d expect from certain clever, real-world developers: the wrong approach developed the wrong way. Fortunately, this program’s author is not one of those developers.

Charles Nadolski is a developer at Strata Marketing, Inc. in Chicago. He was drawn into the wonders of computers after figuring out how to hack his Railroad Tycoon save file to overflow and flip negative twenty million in profits to a positive twenty million. From there it was writing a GOTO-ridden text game in QBASIC and eventually a degree at University of Illinois.

As for the fractions, Charles was inspired by a program his friend wrote for the TI-85 back in high school. It would input any decimal number and turn it into a fraction. He and all of his other math nerds were incredibly impressed by that program’s sheer awesomeness.

And the question I’m sure you all want to know, would Charles replace calc.exe with his own creation?

Only by slipstreaming it onto a Windows install CD first.

Download Entry #100206, Rube Goldberg's Calculator (ZIP File)

[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!