Twenty Four, Again: Difference between revisions

From programming_contest
Jump to navigation Jump to search
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..."
 
imported>Kmk21
No edit summary
 
(2 intermediate revisions by the same user not shown)
Line 5: Line 5:
There are only 10 combinations of parenthesis.
There are only 10 combinations of parenthesis.


(xx)xx
* (xx)xx
x(xx)x
* x(xx)x
xx(xx)
* xx(xx)
(xxx)x
* (xxx)x
((xx)x)x
* ((xx)x)x
(x(xx))x
* (x(xx))x
x(xxx)
* x(xxx)
x((xx)x)
* x((xx)x)
x(x(xx))
* x(x(xx))
(xx)(xx)
* (xx)(xx)


4! * 4^3*10 = 15360
4! * 4^3*10 = 15360
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.