Twenty Four, Again
Jump to navigation
Jump to search
there are only 4! permutations of the numbers.
There are only 4^3 combinations of operators.
There are only 10 combinations of parenthesis.
- (xx)xx
- x(xx)x
- xx(xx)
- (xxx)x
- ((xx)x)x
- (x(xx))x
- x(xxx)
- x((xx)x)
- x(x(xx))
- (xx)(xx)
4! * 4^3*10 = 15360
Just iterate through all of them and find the cheapest.
One of the challenges to this problem SHOULD be to actually evaluate the expression...they want you to use a recursive descent parser (which you SHOULD know how to build....), but you can just dump it in java's javascript engine and call "evaluate" which will evaluate the string-based expression for you.