Problem 54275. Get twenty-four
Inpur four integers in 1 to 10, you may use plus, minus, multiply and divid to get 24. Note that every integer should be used once and only once. Brackets are of no limit, and the result should exactly be 24 once you calculate by hand. (Calculation in computer will lead to a tolerance to the computer precision.)
You need to return a format and a vector with the same four integers, such that you can print the expression.
E.g., input x = [5 5 7 7]
you may return f = '(%d*%d)-(%d/%d)'
and z = [5 5 7 7]
so 24 is obatined by eval(sprintf(f,z)).
The answer is not necessary unique, e.g., other acceptable answers are
f = '(%d*%d)-(%d*%d)'
z = [7 7 5 5]
and f = '(%d-%d)*(%d+%d)'
z = [7 5 7 5]
Solution Stats
Problem Comments
-
2 Comments
Solution Comments
Show commentsProblem Recent Solvers2
Suggested Problems
-
228 Solvers
-
Convert Roman to Arabic Numerals
120 Solvers
-
What is the distance from point P(x,y) to the line Ax + By + C = 0?
554 Solvers
-
Getting the absolute index from a matrix
254 Solvers
-
Given a matrix, swap the 2nd & 3rd columns
1253 Solvers
More from this Author12
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!