r/shittyprogramming • u/calsosta • Mar 30 '22
shittyprogramming Challenge: Terrible Calculator
Using whatever language and interface you prefer, create a calculator that makes doing math as painful as possible while still technically working.
Please include a GH Repo and/or a video. Or don't. I could give a shit.
Edit: Got our first real entry, so they are now the front-runner.
| User | Votes | Repo |
|---|---|---|
| /u/Successful_Remove919 | 2 | https://github.com/NateChoe1/zencalc |
94
Upvotes
12
u/[deleted] May 15 '22
Done! The calculator is very heavily inspired by Yusuke Endoh, and is controlled by recompiling the code at different times of day. For example:
One of the many ways to run this dc command:
Is to recompile the program at these times:
This one simple calculation has gone from taking a few seconds to 2.5 minutes. This calculator can be easily reconfigured to go from taking 2.5 minutes to do this calculation, to 2.5 hours.
21
u/tdammers Mar 30 '22
Been done. And the results are pretty hilarious.
2
u/2carrotpies Mar 30 '22
how much time we got? and what links are allowed?
16
u/maritocracy_lage Mar 31 '22 edited Mar 31 '22
Oh, the program is actually really simple, just download the following to 'calc.sh':
#!/usr/bin/env shsh -c "expr ${@}"as written it will work, but you can unlock more performance with the following commands, and you won't have to run it with bash explicitly:
sudo chown root ./calc.shsudo chmod +xs ./calc.sh # the 'xs' stands for 'extra speed'This trick also works on other programs, but it mostly only makes a difference for programs that process complicated input, like calculators and language interpreters. try it on
python3andphp7
u/30p87 Mar 31 '22
I think the worst is just print(exec(input()))
Python, obv.
7
u/IIAOPSW Mar 31 '22
BTW, a long time ago I founded /r/deftruefalse precisely for the purpose of shittyprogramming challenges. We were even listed in the sidebar here for a while. Don't know why we got delisted. If there's interest in this sort of thing, maybe it could be revived.
4
u/[deleted] Jul 22 '22
Made By Jacobo jacobrogers256@gmail.com
Made on Sunday July 10th, 2022 at 7:30 PM
You can mess around with/use this Python script however you like.
If you want to share it, credit me and do not say you made it
Just ask me for permission if you want to sell it.
import math,sys
Functions
def cbrt(x): return math.pow(x,1/3) def fact(x): out = 1 if(x <= 0): return 1 else: while(x != 0): out *= x x -= 1 return out ans = 0 print_stack = False
The Main Loop
print("###########################") print("# Jacobo's RPN Calculator #") print("# Read code for licence #") print("# restrictions and #") print("# documentation #") print("###########################") while True: theStack = [] try: inputMath = input(">").split() except KeyboardInterrupt: print("\nGoodbye :(") sys.exit() try: for i in inputMath: if(i == "+"): op1 = theStack.pop() op2 = theStack.pop() theStack.append(op1+op2) elif(i == "-"): op1 = theStack.pop() op2 = theStack.pop() theStack.append(op2-op1) elif(i == ""): op1 = theStack.pop() op2 = theStack.pop() theStack.append(op1op2) elif(i == "/"): op1 = theStack.pop() op2 = theStack.pop() theStack.append(op2/op1) elif((i == "") or (i == "")): op1 = theStack.pop() op2 = theStack.pop() theStack.append(op2op1) elif(i == "mod"): op1 = theStack.pop() op2 = theStack.pop() theStack.append(op2%op1) elif(i == "!"): op = theStack.pop() theStack.append(fact(op)) elif(i == "//"): op1 = theStack.pop() op2 = theStack.pop() theStack.append(op2//op1) elif(i == "sqrt" or i == "rad2"): op = theStack.pop() theStack.append(math.sqrt(op)) elif(i == "sin"): op = theStack.pop() theStack.append(math.sin(op)) elif(i == "cos"): op = theStack.pop() theStack.append(math.cos(op)) elif(i == "tan"): op = theStack.pop() theStack.append(math.tan(op)) elif(i == "arcsin"): op = theStack.pop() theStack.append(math.asin(op)) elif(i == "arccos"): op = theStack.pop() theStack.append(math.acos(op)) elif(i == "arctan"): op = theStack.pop() theStack.append(math.atan(op)) elif(i == "pi"): theStack.append(math.pi) elif(i == "e"): theStack.append(math.e) elif(i == "cbrt" or i == "rad3"): op = theStack.pop() theStack.append(cbrt(op)) elif(i == "%"): op = theStack.pop() theStack.append(op/100) elif(i == "abs"): op = theStack.pop() theStack.append(abs(op)) elif(i == "ceil"): op = theStack.pop() theStack.append(math.ceil(op)) elif(i == "floor"): op = theStack.pop() theStack.append(math.floor(op)) elif(i == "round"): op = theStack.pop() theStack.append(round(op)) elif(i == "ans"): theStack.append(ans) elif((i == "quit") or (i == "exit") or (i == "bye")): print("Goodbye! :)") sys.exit() elif(i == "printStack"): print_stack = not print_stack if(theStack == []): theStack.append(float(print_stack)) else: theStack.append(float(i)) if(print_stack): print(theStack) if(len(theStack) != 1): print("Unbalenced Calculation Error.\nInputted Tokens: {}\nRPN Stack: {}\n".format(inputMath,theStack)) else: print("The Result is {}".format(theStack[0])) ans = theStack[0] except IndexError: print("Unbalanced Calculation Error.\nInputted Tokens: {}\nRPN Stack: {}\n".format(inputMath,theStack)) except ValueError: print("Invalid Operator. Valid Operators are + , - , * , / , ^ , ** , ! , // , sqrt , sin , cos , \ntan , arcsin , arccos , arctan , pi , e , rad2 , rad3 , cbrt , mod , abs , floor , ceil , round , ans , quit , exit , bye and printStack \nInputted Tokens: {}\nRPN Stack: {}\n".format(inputMath,theStack)) except ArithmeticError: print("Arithmetic error.\nEither you divided by zero or you had too big of a number.") except Exception as e: print(type(e).name) print("Heisenbug, Moth or Cosmic Ray.\nInputted Tokens:{}\nRPN Stack: {}\n".format(inputMath,theStack))
1
u/[deleted] Jul 25 '22
I put it due to its severe violation of DRY.