Don't overengineer it. Just a Label for all possible results and then a goto from the Inputs. So for example 3+3 and 30/5 both goto 6. Dry, brother, dry
It’ll be more efficient if you remove the spaces around all the symbols on the input, and store all answers in a hash with the equations as key names , then do a lookup in the hash table for the answer. Also probably should add an error message to contact the dev if the provided equation can be “calculated” and be sure to include your email address.
A hash table is obviously the fastest way to go here. But I would personally build an abstract syntax tree, convert that to an immediate representation and compile to byte code.
14
u/[deleted] Apr 04 '26
Those are not equations
71
u/Zombiesalad1337 Apr 04 '26
This is stupid, use a switch instead.
133
u/EvidenceFearless6800 Apr 04 '26
wait until the user doesn't put the spaces between the numbers and witness the program's meltdown
24
u/Ambivalent-Mammal Apr 04 '26
Looks fine to me. I mean how many numbers could there even be ?
9
u/BroMan001 Apr 04 '26
Just
return exec(question)lmao4
u/Cythru Apr 04 '26
Ohhhh that's what you post on programming horror, I listed a programming like tragedy. Check my posts you'll see
3
u/DistearRoyl Apr 04 '26
I feel "equation" needs "=".
3
u/Ro_Yo_Mi Apr 04 '26
It’ll be more efficient if you remove the spaces around all the symbols on the input, and store all answers in a hash with the equations as key names , then do a lookup in the hash table for the answer. Also probably should add an error message to contact the dev if the provided equation can be “calculated” and be sure to include your email address.
3
u/VIBaJ Apr 05 '26
Clearly intentionally bad code posted here is almost always more boring than "natural" programming horror
2
u/LifeIsBulletTrain Apr 04 '26
That has to be a joke
2
u/RunninPigeon Apr 04 '26
op are you yandere dev?
2
u/Savage-Goat-Fish Apr 04 '26
I got to know how long this is.
2
u/RMF_AndyPlayz Apr 04 '26
insert that one image of yandere simulator code
2
u/TRKako [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo “You live” Apr 04 '26
That is so inefficient, this is way better
https://github.com/TomTkacz/Mathless-Calculator
2
u/PhysicalScience7420 Apr 05 '26
def add(values):
sum=0
for i in values:
sum+=i
return sum #sorry for the indentation reddit isnt a code editor
2
u/PhysicalScience7420 Apr 05 '26
holy crap i didnt notice but they used a single string values for everything.
2
u/Apache08 Apr 05 '26
They should ban calculator posts
1
u/ThenotoriousBIT Apr 04 '26
if it works it works xD
1
u/Alphursae Apr 04 '26
Coding is my passion.
1
u/Background-Main-7427 Apr 06 '26
I wonder if besides using 1 + 6 he also did 6 + 1.
1
u/Kooky-Education5683 Apr 06 '26
Congratultions on becoming the world's most sucessful programmer
1
u/Player_903 Apr 07 '26
Maybe do something like :
If you use the space between two in every case...
1
u/Henrique_Backes Apr 09 '26
This is another open-source project from the guy who made is-even in JS
0
u/CakeEaterGames Apr 08 '26
This joke has been done to death at this point