MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi test

Learn moreOpportunities for recent engineering grads.

Apply TodayGiven 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))`

222 correct solutions
482 incorrect solutions

Last solution submitted on Nov 20, 2015

10 players like this problem

1 player likes this solution

1 Comment

Ramoflaple
on 12 Aug 2015

smart cheater :)

1 Comment

Kirk
on 23 Jul 2014

Would be much harder problem if you did not allow repeated index numbers and insisted on numerical index instead of logical

2 Comments

George Berken
on 12 Feb 2014

combnk is not accepted ! ! !
nchoosek works :)

Ramoflaple
on 12 Aug 2015

Should this work for the last test!!!
why does the error "out of memory" not show?

1 Comment

nimin bbs
on 31 Jan 2014

This is not the shortest, but it is a oneliner.

1 Comment

Thomas Vanaret
on 30 Oct 2013

Only allowed by a too simple test suite...

1 player likes this solution

1 Comment

Thomas Vanaret
on 30 Oct 2013

This should be the best noted solution :
- No brute-force search
- No "regexp" trick
- No cheating (allowed by a too simple test suite)

6 players like this solution

2 Comments

Jean-Marie Sainthillier
on 17 Mar 2013

Wonderful solution with a factorization of ans.

Ramoflaple
on 12 Aug 2015

make full use of "half of the sum"

13 Comments