I recently had to add a small basic calculator to a project. I wrote a quick dirty one, but it seemed small enough to check with you people out here ;)

Just out of curiosity & an appetite to get surprised for some real hacky solutions, try and beat this one :


function scalcy() {
    var b="", p=parseFloat,t,i;
    return $("<div>").append("789/456*123-.0=+".split("").map(function(i){
        return $("<button/>").text(i).width(32).height(32).click(function(){
        b = (!p(i=$(this).text())? b.replace(/\D+$/,""): b) + i;        
        t.val(((!(i.match(/[.\d]/))? (b=eval(b.slice(0,-1))+i+"").slice(0,-1):
                p(b.match(/[.\d]+/g).pop()) || 0) + "").slice(0,8));

Screenshot (in chrome): (DEMO)

enter image description here

Considerations: Better the UI & lesser the bugs, the better.

Minimum Functionalities:

  • Supports floating point arithmetic (/*-+),
  • Reset feature,
  • Continuous Operation (like working on with the last result)


  • Use any language & library, but please not a library call like new calculator().
  • Forking the above code itself is most welcome.

Additional Notes:

  • A graphical UI is obviously considered better than not having any at all.
  • I'd suggest to have a look at this challenge (for inspiration): Create a GUI Piano.
  • 4
    \$\begingroup\$ What is the objective winning criteria? How do you measure how great a UI is? \$\endgroup\$ Commented Sep 5, 2013 at 8:15
  • \$\begingroup\$ Basically the calculator should look like the calculator we all know, some buttons & a textbox (like the image above). No sacrifices to be made on that.. \$\endgroup\$
    – loxxy
    Commented Sep 5, 2013 at 11:27
  • \$\begingroup\$ I don't like to duplicate UI things (and support only the new one). I have thoose buttons on my keyboard, which don't work on your solution. \$\endgroup\$ Commented Sep 5, 2013 at 11:31
  • 2
    \$\begingroup\$ Congratulations, you just made a chamelion question that invalidated a previously valid answer. \$\endgroup\$ Commented Sep 5, 2013 at 12:14
  • 2
    \$\begingroup\$ @loxxy Maybe no one else attempts a question which is not well-specified and has no objective winning criterion. Reading and following the comments usually generates better questions and also more interest in solving them. \$\endgroup\$
    – Howard
    Commented Sep 5, 2013 at 13:15

1 Answer 1


Tcl/Tk, 100

pack [entry .e -textv e] -f both -e 1
bind . <Return> {catch {expr $e} e}
bind . <Escape> {set e {}}

Buttons are not required, so leave them alone.
The GUI is great. So simple that you can finally focus on the task that you try to do.

  • 1
    \$\begingroup\$ I'm not familiar with the language, so I need to ask: This isn't using a text-based interface, as opposed to graphical one? \$\endgroup\$
    – shiona
    Commented Sep 4, 2013 at 16:02
  • 2
    \$\begingroup\$ Tk is a graphical toolkit. Yes, it has a window and so on. Just no buttons :P \$\endgroup\$ Commented Sep 4, 2013 at 16:26
  • 5
    \$\begingroup\$ Upvoted for strict interpretation of rules... one of my favorite games on this site. \$\endgroup\$
    – boothby
    Commented Sep 5, 2013 at 1:58
  • 1
    \$\begingroup\$ You only save 12 characters (bind <>) for in exchange for the lmap and list formating. Yes, this trade of isn't worth it most of the time. \$\endgroup\$ Commented May 2, 2018 at 0:21
  • 1
    \$\begingroup\$ Outgolfed: 106 \$\endgroup\$
    – sergiol
    Commented May 2, 2018 at 0:21

Not the answer you're looking for? Browse other questions tagged or ask your own question.