Problem 660. Find a subset that divides the vector into equal halves
Given a vector x, return the indices to elements that will sum to exactly half of the sum of all elements.
Example:
Input x = [1 2 3 4 5 6 7] Output xi = [1 6 7]
because
sum(x) = 28 sum(x([1 6 7])) = 14
The answer is not necessarily unique and the order is unimportant. We will just test to make sure that sum(x)/2 is sum(x(xi))
Solution Stats
Problem Comments
-
14 Comments
Could you please post the link to ASEE Challenge June 10-13? Thanks!
Amitava, do you mean here? The link is http://www.mathworks.com/matlabcentral/cody/?sort=created+desc&term=group%3A%22ASEE+Challenge%22
it seems that tests no3 and no4 are incorrectly defined. Ned, check this out please.
@Vieniava, can you be more specific? The tests are the same in all cases. I did verify that Solution 173962 does indeed get an incorrect answer to tests 3 and 4.
This was fun
A lot a very beautiful solutions.
What was changed on 5th. November?? :-/
I added a new test. I periodically strengthen test suites to defeat look-up table strategies.
I solved this with matlab inbuilt function 'combnk'. Is that not allowed? It gives me the error 'Undefined function' everytime I run my solution.
Aryaa: Your solution looks good. The problem is that combnk is in the Statistics Toolbox, and Cody is designed to use only functions from basic MATLAB.
I used random numbers, but couldn't get it. :( (worked fine in my laptop.) :( I guess I haven't completely understood the question. :((
why do i get internal server error :(((
Hassan, where are you getting an internal server error? Maybe leave your comment on the solution that has the related error? I'm guessing that your solution relies on randomness, so if you don't get lucky, the answer will time out. You may get lucky on your computer, but not on the Cody server.
A basic one liner with intlinprog, but not an option in Cody. :)
Solution Comments
Show commentsProblem Recent Solvers387
Suggested Problems
-
7289 Solvers
-
498 Solvers
-
Try 1.5.4: Celsius to Fahrenheit
806 Solvers
-
326 Solvers
-
Sum of odd numbers in a matrix
567 Solvers
More from this Author50
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!