While going through contest entries, we were bummed that we don't have more high-res JPGs (and laptops) to give out. Here are some highlights that didn't quite make finalists, but got the Honorable Mention award. For which the prize is an honorable mention in this article. This is the third and final entry in a three-part series.
Massimo's ASMCalc avoids expensive built-in arithmetic functions, instead using a function pointer to assembly code patched at runtime:
int ASMCode[] = { 0x83EC8B55, 0x565340EC, 0x0845DD57, 0x5F1045DC, 0xE58B5B5E, 0x9090C35D };ASMCalc
Tony Sherwood is a jerk to his friend Paula Bean (see code comments):
/* Title: PaulaCalc v1.0 Author: Paula Bean Date: 04/15/07 Brief Description: A friend of mine from college called me the other day, and told me about this contest to write the best C++ calculator program you could. He said he was always impressed by my code back in school, and that when he heard about the contest I was the first person he thought of... anyways, first place is 20 dollars! The only thing is that you have to be a member of the site to join the contest, so he offered me half the prize money if I agreed to write the program and he would submit it. So, here goes: I've never worked in C++ before, but how hard could it be? This should be fun. */ string paula = "Brillant"; string getPaula() { return paula; } //WHAT KIND OF PROGRAMMING LANGUAGE DOESN'T EVEN HAVE TOSTRING()?!?! string floatToString(float f) { stringstream s; s << f; return s.str(); } // OR EVEN TRIM()?! GOOD GOD... WTF WERE THEY THINKING?! void trim(string& str) { string::size_type pos = str.find_last_not_of(' '); if(pos != string::npos) { str.erase(pos + 1); pos = str.find_first_not_of(' '); if(pos != string::npos) str.erase(0, pos); } else str.erase(str.begin(), str.end()); }PaulaCalc v1.0
CrazyCoder's experimented with fredsafety.
// for Fred's safety while (is_calculating == 1) { //break; // slow down computation int dummy = 0; //DEBUG("dfhdfhhd", 0); dummy *= dummy; dummy * dummy * dummy; // division is said to be slow dummy = dummy / dummy / dummy; dummy = dummy * dummy * dummy; dummy = dummy / dummy / dummy; dummy = dummy * dummy * dummy; dummy = dummy / dummy / dummy; dummy = dummy * dummy * dummy; dummy = dummy / dummy / dummy; dummy = dummy * dummy * dummy; } is_calculating++; // we are calculatingYatCalc 7.0 Pro
Steve Hawley created his own Lisp-like language and parser. In his words, "You'll note that the calculator buttons are bound to lisp programs instead of vectoring through C code. This teensy hit in efficiency is clearly outweighed by the added flexibility." half-ass-expr
jlahd built an extensible calculator claculator that makes extensive use of generics and the registry, making updates simple should the definition of numbers, operators, or math ever change.
// Digit strings ClaculatorConstant<char const*> claculator_constant_digit_0( "0", "digit_0" ); ClaculatorConstant<char const*> claculator_constant_digit_1( "1", "digit_1" ); ClaculatorConstant<char const*> claculator_constant_digit_2( "2", "digit_2" ); ClaculatorConstant<char const*> claculator_constant_digit_3( "3", "digit_3" ); ClaculatorConstant<char const*> claculator_constant_digit_4( "4", "digit_4" ); ClaculatorConstant<char const*> claculator_constant_digit_5( "5", "digit_5" );Claculator
Michael Ensly is completely nvts. His calcvlator converts all digits to Roman nvmerals behind the scenes. It also inclvded a clever interface with all cvstom artwork. Definitely worth a download and compile.
// Simplify result by summation of internal numerals: op1 = replace( replace( replace( replace( replace( replace( op1, "IIIII","V"), "VV","X"), "XXXXX","L"), "LL","C"), "CCCCC","D"), "DD","M"); op1 = AddSubNot(op1); // Apply subtractive notation return op1;Romanorum Computus
Steven Burnap did an impressive amount of WTFing in his "Fourth Calculator." Here are some brief snippets:
///////////////////////////////////////////////////////////////////// // // Program: Calculator Engine // Version: 1.01rc6 RELEASE // Author: Wally T. Farnsworth, PhD. // Company: Farnsworth Consulting International, ltd. // // Copyright (c) Wally T. Farnsworth, PhD. All Rights Reserved under the GPL!! // // Changelist: // // Date Version User Comment // 05/01/2007 0.1 WTF Initial version // 05/01/2007 0.1a WTF Forth engine // 05/03/2007 0.11 WTF Add '+', '-' to Forth engine // 05/05/2007 0.12 WTF Add '*', '/' to Forth engine // 05/07/2007 0.13 WTF Optimize Forth engine // 05/08/2007 0.14 WTF OO Wrapper to interface with C++ // 05/09/2007 0.5 WTF Misc. bug fixes // 05/10/2007 0.51 WTF Refactor OO wrapper // 05/11/2007 0.6 WTF Add operator classes to OO wrapper // 05/12/2007 0.9 WTF Add threading // 05/12/2007 1.0 WTF Connect to calculator. // 05/12/2007 1.001 WTF Bug fixes // 05/13/2007 1.001a WTF Bug fixes // 05/13/2007 1.001b WTF Bug fixes // (snipped around 30 lines of "Bug fixes" on 5/13/2007) // 05/13/2007 1.01rc4 WTF Bug fixes // 05/13/2007 1.01rc5 WTF Bug fixes // 05/13/2007 1.01rc6 WTF No bugs!!! Done!!! ////////////////////////////////////////////////////////////////////////////// #include "calcfunc.h" #define WIN32 // TODO Figure out why this needs to be defined/ // snip ////////////////////////////////////////////////////////// // Class: Mutex // For some reason, the stupid Windows threads cause the CPU to max out in the mutex, // so I made my own cooperative multitasking system. ////////////////////////////////////////////////////////////Fourth Calculator
Kellen Mickley runs all calculations in brainfsk. Brainfsk Variation
Chicken Little entered like 30 calculators into the competition. Here's a little piece of one of them that we liked:
if (*PointerTo_op1 == Eight && *RightOp == Four) { *PointerToTheResult++ = BorrowTheOne == true ? Three : *RightOp; BorrowTheOne = false; }ChickenCalc
We received several hardware emulation entries, all of which were fantastic. Goplat's, though, would parse through an ASCII representation of a series of logic gates.
const char cpu[HEIGHT][WIDTH] = { /*Result TC C Acc Operand IP S InsnA InsnB */ " ! ! !!!!!!!! !!!!!!!! ! !!!!!!!! !!!!!!!! ", " | | |||||||| |||||||| >---++++++++-++++++++----` ", " | | |||||||| |||||||| | |||||||| |||||||>-xa-< ", " | | |||||||| |||||||>---+---++++++++-++++++++-^x-+-!", " | | |||||||| |||||||| | |||||||| ||||||>+-x-a< ", " | | |||||||| ||||||>+---+---++++++++-++++++++-^-x+-!", " | | |||||||| |||||||| | |||||||| |||||>++-xa-< ", " | | |||||||| |||||>++---+---++++++++-++++++++-^x-+-!", " | | |||||||| |||||||| | |||||||| ||||>+++-x-a< ", " | | |||||||| ||||>+++---+---++++++++-++++++++-^-x+-!", " | | |||||||| |||||||| | |||||||| |||>++++-xa-< ", " | | |||||||| |||>++++---+---++++++++-++++++++-^x-+-!", " | | |||||||| |||||||| | |||||||| ||>+++++-x-a< ", " | | |||||||| ||>+++++---+---++++++++-++++++++-^-x+-!", " | | |||||||| |||||||| | |||||||| |>++++++-xa-< ", " | | |||||||| |>++++++---+---++++++++-++++++++-^x-+-!", " | | |||||||| |||||||| | |||||||| >+++++++-x-a/ ", " | | |||||||| >+++++++---+---++++++++-++++++++-^-x--!", " | | |||||||| |||||||| /-< |||||||| |||||||| ", " | | ||||||||/------------++++++++-a >n--++++++++o++++++++----` ", " | | ||||||||| |||||||| `-+---++++++<>/|||||||`-vx-+-!", " | | |||||||>+-xv---------++++++++---+---++++++++-+++++++--xa-< ", " | | ||||||||>-ax-------` |||||||| | |||||||| ||||||`+-v-x+-!", " | | ||||||>++x-v-------+-++++++++---+---++++++++-++++++---x-a< ", " | | ||||||||>a-x------`| |||||||| | |||||||| |||||`++-vx-+-!", " | | |||||>+++-xv------++-++++++++---+---++++++++-+++++----xa-< ", " | | ||||||||>-ax-----`|| |||||||| | |||||||| ||||`+++-v-x+-!", " | | ||||>++++x-v-----+++-++++++++---+---++++++++-++++-----x-a< ", " | | ||||||||>a-x----`||| |||||||| | |||||||| |||`++++-vx-+-!", " | | |||>+++++-xv----++++-++++++++---+---++++++++-+++------xa-< ", " | | ||||||||>-ax---`|||| |||||||| | |||||||| ||`+++++-v-x+-!", " | | ||>++++++x-v---+++++-++++++++---+---++++++++-++-------x-a< ", " | | ||||||||>a-x--`||||| |||||||| | |||||||| |`++++++-vx-+-!", " | | |>+++++++-xv--++++++-++++++++---+---++++++++-+--------xa-< ", " | | ||||||||>-ax-`|||||| |||||||| | |||||||| `+++++++-v-x+-!", " /---+-< >++++++++x-v-+++++++-++++++++---+---++++++++----------x-a/ ", " | | | ||||||||`a-x`||||||| |||||||| | |||>++++------` ", " | | >-------++++++++----++++++++-++++++++---+---++++++++-v--vx+--------`", " o-n-+-+----v--++++++++----++++++++-++++++++---+---++<||||| | xa< |", " | | | /-+--++++++++----++++++++-++++++++---+---+++<|||| | | | |", " /< | | /</< |||||||| |||||||>-++++++++---+---++++++++-+-v+x+-------`|", " /-+x/v-+-+-x+a+--+++++++< |||||||| |||||||| | |||||||| | |||| ||", " | a^+x | | | | |||||||| |||||||| |||||||| | |||||||| | x+a< ||", " | `oa^-+-+--+-+--++++++++----+++++++< |||||||| | |||||||| | || | ||", " | /< | | /</< |||||||| ||||||>+-++++++++---+---++++++++-+-+*x+------`||", " /+-+x/v-+-+-x+a+--++++++<| |||||||| |||||||| | |||||||| | |||| |||", " || a^+x | | | | |||||||| |||||||| |||||||| | |||||||| | |xa< |||", " || `oa^-+-+--+-+--++++++++----++++++<| |||||||| | |||||||| | || | |||", " || /< | | /</< |||||||| |||||>++-++++++++---+---++++++++-+-*+x+-----`|||", " /++-+x/v-+-+-x+a+--+++++<|| |||||||| |||||||| | |||||||| | |||| ||||", " ||| a^+x | | | | |||||||| |||||||| |||||||| | |||||||| | x+a< ||||", " ||| `oa^-+-+--+-+--++++++++----+++++<|| |||||||| | |||||||| | || | ||||", " ||| /< | | /</< |||||||| ||||>+++-++++++++---+---++++++++-+-+*x+----`||||", " /+++-+x/v-+-+-x+a+--++++<||| |||||||| |||||||| | |||||||| | |||| |||||", " |||| a^+x | | | | |||||||| |||||||| |||||||| | |||||||| | |xa< |||||", " |||| `oa^-+-+--+-+--++++++++----++++<||| |||||||| | |||||||| | || | |||||", " |||| /< | | /</< |||||||| |||>++++-++++++++---+---++++++++-+-*+x+---`|||||", " /++++-+x/v-+-+-x+a+--+++<|||| |||||||| |||||||| | |||||||| | |||| ||||||", " ||||| a^+x | | | | |||||||| |||||||| |||||||| | |||||||| | x+a< ||||||", " ||||| `oa^-+-+--+-+--++++++++----+++<|||| |||||||| | |||||||| | || | ||||||", " ||||| /< | | /</< |||||||| ||>+++++-++++++++---+---++++++++-+-+*x+--`||||||", " /+++++-+x/v-+-+-x+a+--++<||||| |||||||| |||||||| | |||||||| | |||| |||||||", " |||||| a^+x | | | | |||||||| |||||||| |||||||| | |||||||| | |xa< |||||||", " |||||| `oa^-+-+--+-+--++++++++----++<||||| |||||||| | |||||||| | || | |||||||", " |||||| /< | | /</< |||||||| |>++++++-++++++++---+---++++++++-+-*+x+-`|||||||", " /++++++-+x/v-+-+-x+a+--+<|||||| |||||||| |||||||| | |||||||| | |||| ||||||||", " ||||||| a^+x | | | | |||||||| |||||||| |||||||| | |||||||| `-x+a/ ||||||||", " ||||||| `oa^-+-+--+-+--++++++++----+<|||||| |||||||| | |||||||| | /////////", " ||||||| /< | | /</< |||||||| >+++++++-++++++++---+---++++++++----/ ///////// ", " /+++++++-+x/v-+-+-x+a+--<||||||| |||||||| |||||||| | |||||||| ///////// ", " |||||||| a^+x | | | | |||||||| |||||||| |||||||| | |||||||| ///////// ", " |||||||| `oa^-+-+--+-+--++++++++----<||||||| |||||||| | |||||||| |||||||| ", " /++++++++--/ /-+-+--+-+--++++++++----++++++++-++++++++---+---+<|||||| |||||||| ", " ||||||||`-vx-+-+-+--+-+--++++++++----++++++++-++++++++---+---++++++++----+++++++/ ", " ||||||||/-xa-< | | | | |||||||| |||||||>-++++++++---+---++++++++----+++++++` ", " |||||||`+-v-x+-+-+--+-+--++++++++----++++++++-++++++++---+---++++++++----++++++/| ", " |||||||/+-x-a< | | | | |||||||| ||||||>+-++++++++---+---++++++++----++++++`| ", " ||||||`++-vx-+-+-+--+-+--++++++++----++++++++-++++++++---+---++++++++----+++++/|| ", " ||||||/++-xa-< | | | | |||||||| |||||>++-++++++++---+---++++++++----+++++`|| ", " |||||`+++-v-x+-+-+--+-+--++++++++----++++++++-++++++++---+---++++++++----++++/||| ", " |||||/+++-x-a< | | | | |||||||| ||||>+++-++++++++---+---++++++++----++++`||| ", " ||||`++++-vx-+-+-+--+-+--++++++++----++++++++-++++++++---+---++++++++----+++/|||| ", " ||||/++++-xa-< | | | | |||||||| |||>++++-++++++++---+---++++++++----+++`|||| ", " |||`+++++-v-x+-+-+--+-+--++++++++----++++++++-++++++++---+---++++++++----++/||||| ", " |||/+++++-x-a< | | | | |||||||| ||>+++++-++++++++---+---++++++++----++`||||| ", " ||`++++++-vx-+-+-+--+-+--++++++++----++++++++-++++++++---+---++++++++----+/|||||| ", " ||/++++++-xa-< | |/-/ | |||||||| |>++++++-++++++++---+---++++++++----+`|||||| ", " |`+++++++-v-x+-+-++---+--++++++++----++++++++-++++++++---+---++++++++----/||||||| ", " |/+++++++-x-a< | ||/--/ |||||||| >+++++++-++++++++---+---++++++++----`||||||| ", "!+++++++++----+-+-+++-----++++++++----++++++++-++++++++--a+---+++++<|| |||||||| ", " `++++++++--` | | |||/----++++++++----++++++++-++++++++-a*< |||||||| |||||||| ", "!-+++++++^--+-+-+-++++-xv-+++++++/ |||||||| |||||||| `++---++++<||| |||||||| ", " ||||||| | | | |||>-ax-+++++++` |||||||| |||||||>--++-v-++++++++-n-`|||||||| ", "!-++++++^---+-+-+-++++x-v-++++++/| |||||||| `+++++++` || | |||||||`vx-++++++++< ", " |||||| | | | |||>a-x-++++++`| |||||||| /+++++++x`|| | |||||||/xa-<|||||||| ", "!-+++++^----+-+-+-++++-xv-+++++/|| |||||||| |`++++++va|| | ||||||`+v-x+++++++<| ", " ||||| | | | |||>-ax-+++++`|| |||||||| |/++++++x<|| | ||||||/+x-a<|||||||| ", "!-++++^-----+-+-+-++++x-v-++++/||| |||||||| ||`+++++va|| | |||||`++vx-++++++<|| ", " |||| | | | |||>a-x-++++`||| |||||||| ||/+++++x<|| | |||||/++xa-<|||||||| ", "!-+++^------+-+-+-++++-xv-+++/|||| ///////// |||`++++va|| | ||||`+++v-x+++++<||| ", " ||| | | | |||>-ax-+++`|||| ///////// |||/++++x<|| | ||||/+++x-a<|||||||| ", "!-++^-------+-+-+-++++x-v-++/||||| ///////// ||||`+++va|| |/<||`++++vx-++++<|||| ", " || | | | |||>a-x-++`||||| |||||||| ||||/+++x<|| |||||/++++xa-<|||||||| ", "!-+^--------+-+-+-++++-xv-+/|||||| |||||||| |||||`++va|| ||||`+++++v-x+++<||||| ", " | | | | |||>-ax-+`|||||| |||||||| |||||/++x<|| ||||/+++++x-a<|||||||| ", "!-^---------+-+-+-++++x-v-/||||||| |||||||| ||||||`+va|>`|||`++++++vx-++<|||||| ", " /---+-+-+-+<|`a-x-`||||||| |||||||| ||||||/+x<|n||||/++++++xa-<|||||||| ", " /---+---+-/ | ||| |||||||| |||||||| |||||||`va|||||`+++++++v-x+<||||||| ", " | /-+xv-+---+-+++-----++++++++-<||||||| |||||||/x^+/|||/+++++++x-a/|||||||| ", " | | `ax-+---+-+++-----++++++++-+++++++</---++++++++--+-a+/|||||||| ///////// ", " | `-x-v-//--+-+++-----++++++++-+++++++++---++++++++--/ | |||||||| ///////// ", " >---a-x-v+xv^-+++-` |||||||| |||||||`+-xv+++++++/ | |||||||| ///////// ", " | |>ax` ||| | /-++++++++-+++++++-a-ax+++++++` /-/ |||||||| |||||||| ", " | |a--+-++/ | n |||||||| ||||||`-+x-v++++++/| | |||||||| |||||||| ", " | `+xv+-^+--+`| |||||||| |||||| >a-x++++++`| | |||||||| |||||||| ", " | `ax+-`| ||| |||||||| |||||`--+-xv+++++/|| | |||||||| |||||||| ", " | | || x<| |||||||| ||||| >-ax+++++`|| | |||||||| |||||||| ", " `-----------+-++--ax| |||||||| ||||`---+x-v++++/||| | |||||||| |||||||| ", " | |`---x/ |||||||| |||| >a-x++++`||| | |||||||| |||||||| ", " | | |||||||| |||`----+-xv+++/|||| | |||||||| |||||||| ", " | | |||||||| ||| >-ax+++`|||| | |||||||| |||||||| ", " | | |||||||| ||`-----+x-v++/||||| | |||||||| |||||||| ", " | | |||||||| || >a-x++`||||| | |||||||| |||||||| ", " | | |||||||| |`------+-xv+/|||||| | |||||||| |||||||| ", " | | |||||||| | >-ax+`|||||| | |||||||| |||||||| ", " | | |||||||| `-------+x-v/||||||| | |||||||| |||||||| ", " | | |||||||| >a-x`||||||| | |||||||| |||||||| ", " ! ! !!!!!!!! !!!!!!!! ! !!!!!!!! !!!!!!!! ", }; const unsigned char addprog[] = { 0x19, 0x84, // mov a,84 0x25, 0x80, // add 80 0x19, 0x85, // mov a,85 0x25, 0x81, // add 81 0x19, 0x86, // mov a,86 0x25, 0x82, // add 82 0x19, 0x87, // mov a,87 0x25, 0x83, // add 83 0x15, 0xFF, // mov FF (halt) }; const unsigned char subprog[] = { 0x70, 0x01, // shr #01 (set carry) 0x19, 0x84, // mov a,84 0x35, 0x80, // sub 80 0x19, 0x85, // mov a,85 0x35, 0x81, // sub 81 0x19, 0x86, // mov a,86 0x35, 0x82, // sub 82 0x19, 0x87, // mov a,87 0x35, 0x83, // sub 83 0x15, 0xFF, // mov FF (halt) }; // 16x16 -> 32 multiplication const unsigned char mulprog[] = { 0x18, 0x00, // 00: mov a,#00 0x16, 0x82, // 02: mov 82,a 0x16, 0x83, // 04: mov 83,a 0x14, 0xEF, // 06: mov EF,#EF 0x75, 0x83, // 08: shr 83 0x75, 0x82, // 0A: shr 82 0x75, 0x81, // 0C: shr 81 0x75, 0x80, // 0E: shr 80 0x80, 0x1C, // 10: jcc #1C 0x70, 0x00, // 12: shr #00 (clear carry) 0x19, 0x84, // 14: mov a,84 0x25, 0x82, // 16: add 82 0x19, 0x85, // 18: mov a,85 0x25, 0x83, // 1A: add 83 0x05, 0xEF, // 1C: inc EF 0xC0, 0x08, // 1E: jtc #08 0x15, 0xFF, // 20: mov FF (halt) }; // 32x24 -> 32 division const unsigned char divprog[] = { 0x18, 0x00, // 00: mov a,#00 0x16, 0x88, // 02: mov 88,a 0x16, 0x89, // 04: mov 89,a 0x16, 0x8A, // 06: mov 8A,a 0x14, 0xDF, // 08: mov DF,#DF 0x65, 0x80, // 0A: shl 80 0x65, 0x81, // 0C: shl 81 0x65, 0x82, // 0E: shl 82 0x65, 0x83, // 10: shl 83 0x65, 0x88, // 12: shl 88 0x65, 0x89, // 14: shl 89 0x65, 0x8A, // 16: shl 8A 0x90, 0x2A, // 18: jcs #2A 0x70, 0x01, // 1A: shr #01 (set carry) 0x19, 0x84, // 1C: mov a,84 0x31, 0x88, // 1E: sub -,88 0x19, 0x85, // 20: mov a,85 0x31, 0x89, // 22: sub -,89 0x19, 0x86, // 24: mov a,86 0x31, 0x8A, // 26: sub -,8A 0x80, 0x38, // 28: jcc #38 0x19, 0x84, // 2A: mov a,84 0x35, 0x88, // 2C: sub 88 0x19, 0x85, // 2E: mov a,85 0x35, 0x89, // 30: sub 89 0x19, 0x86, // 32: mov a,86 0x35, 0x8A, // 34: sub 8A 0x70, 0x01, // 36: shr #01 (set carry) 0x05, 0xDF, // 38: inc DF 0xC0, 0x0A, // 3A: jtc #0A 0x15, 0xFF, // 3C: mov FF (halt) };goplatcalc
We'll be announcing the winners next week, so until then, please complain about how boring these calculator articles are in the comments. Thanks in advance!