Problem 2360. Fill an array given a sum and array length values
Solution Stats
Problem Comments
-
1 Comment
Tricky problem !!
Solution Comments
-
1 Comment
At the end, apply sum_array(permute(n)). Or you could use actual random numbers using this same technique, but there maybe repeated values.
-
1 Comment
lucky shot
-
1 Comment
well done guillaume, thanks for trying random numbers as well. great effort!
-
1 Comment
well done alfonso, thanks for trying random numbers as well. im learning new techniques here as well.
-
4 Comments
well done. alfonso how can i amend the problem so that the coder will be forced to generate random values? :)
true randomness is a bit involved to test (particularly without the stats toolbox), plus the sum constrain adds some additional complexity to the randomness of the resulting values (see for example this Cody problem: http://www.mathworks.com/matlabcentral/cody/problems/331-compute-area-from-fixed-sum-cumulative-probability). In any way, the simplest solution to discourage this sort of extremely-non-random solutions would probably be running your current testsuite twice (with identical inputs) and then checking that the returned vectors are different...
Another possibility, would be to test that there is no repetition in the returned values, which can easily be tested with: assert(all(diff(sort(sum_array))));
you're right guillaume, i apppreciate that.
-
3 Comments
Problem Recent Solvers24
Suggested Problems
-
3737 Solvers
-
2389 Solvers
-
Construct a string from letters and counts
138 Solvers
-
Calculate the Number of Sign Changes in a Row Vector (No Element Is Zero)
473 Solvers
-
495 Solvers
More from this Author6
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!