Cody

# Problem 2356. Simulating the selection of a state with given probabilities

Solution 704672

Submitted on 22 Jul 2015
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

### Test Suite

Test Status Code Input and Output
1   Fail
%% probs = rand; while sum(probs) < 1 a = rand; if a + sum(probs) > 1 probs = [probs 1-sum(probs)]; break; else probs = [probs a]; end end states = 1:length(probs); for i = 1:100 y{i,1} = select_state(probs); [nelements,centers] = hist(y{i},states); probs_result{i} = nelements/length(y{i}); error(i,1) = sum(abs(probs-probs_result{i})); end assert(mean(error) <= 0.05 & mean(error) > 0);

j = 0.5495 j = 0.6577 j = 0.9411 j = 0.1859 j = 0.3971 j = 0.0625 j = 0.4956 j = 0.6488 j = 0.4598 j = 0.1371 j = 0.3443 j = 0.7911 j = 0.0180 j = 0.1172 j = 0.2938 j = 0.5012 j = 0.8735 j = 0.1381 j = 0.4485 j = 0.2160 j = 0.7238 j = 0.7400 j = 0.1725 j = 0.7717 j = 0.8165 j = 0.0325 j = 0.1060 j = 0.7342 j = 0.0360 j = 0.3121 j = 0.4880 j = 0.2956 j = 0.8615 j = 0.1228 j = 0.7385 j = 0.3055 j = 0.5650 j = 0.5025 j = 0.0054 j = 0.5986 j = 0.0423 j = 0.0362 j = 0.3834 j = 0.0849 j = 0.4796 j = 0.1479 j = 0.3389 j = 0.5837 j = 0.8904 j = 0.3312 j = 0.5201 j = 0.1852 j = 0.3971 j = 0.6613 j = 0.7926 j = 0.8119 j = 0.6431 j = 0.7605 j = 0.4561 j = 0.2731 j = 0.5882 j = 0.9641 j = 0.5241 j = 0.6393 j = 0.4798 j = 0.8405 j = 0.0230 j = 0.7274 j = 0.4724 j = 0.2539 j = 0.3628 j = 0.5956 j = 0.0089 j = 0.9550 j = 0.4553 j = 0.9504 j = 0.9108 j = 0.0908 j = 0.8101 j = 0.7827 j = 0.7307 j = 0.8591 j = 0.1205 j = 0.5053 j = 0.5276 j = 0.2072 j = 0.6805 j = 0.8516 j = 0.9071 j = 0.0643 j = 0.1907 j = 0.3032 j = 0.6441 j = 0.6247 j = 0.2052 j = 0.3765 j = 0.1334 j = 0.9273 j = 0.9605 j = 0.1615

Assertion failed.