Well, I have begun going back to work on the arithmetic solver calculator thingamabob I was ranting about last time. So far, I have not really had any problems getting it to solve parentheses nested within one another. I am using a recursive call to the function to get it to simplify the parentheses. It works something like this:

- Take an input. For example, 3*(4*2-4-(33/11)-5) is a viable input.
- The function checks for parentheses. In this case, there are parentheses involved. The way this works is that all other terms within parentheses inside the parentheses currently selected are being passed on as arguments for the recursive call to the function. I’m not really feeling verbose at the moment, so I’ll explain using the preformatted thing I did last post:
Take input and search for first parenthesis nest should there be are any. Found nest: (4*2-4-(33/11)-5) Call the function recursively and pass this in as an argument to simplify. Found nest: (33/11) No other nests found in third call to function. Begin solving nests: (33/11) = 3 The function who called the function will get 3 returned. That function will then solve its nest: (4*2-4-3-5) = -4 Return -4 to base function and solve: 3*-4 = -4 ... ... Wait, what?

You see, the way that I originally set up the function means it can’t really cope with negative factors very well. This means that it reads 3*-4 as “three times… what the fuck? Okay, skip that. Negative four. I’ll return negative four.” Because of this, I’ll have to work around this by restructuring the expression as -3*4, which would yield the same result. I actually should, and would, really, go back to the function and clean it up for the sake of making it a bit more efficient and easier to work with. However, considering the massive amount of asspain that was rendered upon me during the ten-fucking-hours-or-so I spent cobbling this fuckfest of a function together, I really just don’t want to go through any more clusterfucks of vectors and booleans and strings and complicated function calls using the difference between vector values as inputs, as well as converting strings to numerical values. It was a fucking nightmare. And, to top it all off, I looked up calculators on some website (maybe cplusplus.com) where everybody had these ultra-clean-looking calculator while I’m sitting here with my behemoth of vectors and all that shit!

Anyway, I gotta get back to working on fixing the problem with the negative factors and polishing it so that it actually works with more than just one nest of parentheses.

Pingback: Java Log – Entry #3 | RGGs::Programming();