Twenty Four, Again: Difference between revisions
Jump to navigation
Jump to search
imported>Kmk21 No edit summary |
imported>Kmk21 No edit summary |
||
Line 27: | Line 27: | ||
[[Category:Implementation Medium]] | [[Category:Implementation Medium]] | ||
[[Category:Brute Force]] | [[Category:Brute Force]] | ||
[[Category:Javascript]] | |||
[[Category:Parsing]] |
Latest revision as of 02:44, 2 November 2017
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.