I primarily code in JavaScript, but also know many other languages. I absolutely love to program and have loved it ever since I was a little kid. Check out my work at http://kiraprograms.com!
I primarily code in JavaScript, but also know many other languages. I absolutely love to program and have loved it ever since I was a little kid. Check out my work at http://kiraprograms.com!
Very nice.
You might make it a lot simpler by restructuring it as a set of more regular rewrite rules operating on a structured representation.
Thanks a ton for the advice! Do you mean that it would have been simpler first turn it into an expression tree, then simplify it?
Yes, I think so.
Perhaps even a representation as simple as:
Then you can imagine a recursive walk over that expression using a rule that matches
[op('+'), number, number]
and rewrites it to the sum, reducing that to
['*', 3, 5]
, and another rule like
[op('*'), number, number]
and reduces that to 15, and then you're done.
Great idea, thanks!