Twenty Four, Again

From programming_contest
Revision as of 02:42, 2 November 2017 by imported>Kmk21 (Created page with "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...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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.