Cody

# Problem 1089. Create a random vector of integers with given sum

Solution 2293265

Submitted on 18 May 2020 by Ilia Belskii
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   Pass
nocheat = isempty(regexp(evalc('type random_sequence'),'([^f]eval|regexprep|inline|str2func)')); m = 26; s = 5000; y = random_sequence(m,s); assert(isequal(sum(y),s) && abs(mean(y)-m/2)<m*sqrt(m/s)+1/2 && isequal(y,round(y)) && abs(std(y)-m/sqrt(12))*sqrt(s)/m<2.5 && nocheat)

y = Columns 1 through 30 18 20 15 3 24 7 2 24 11 20 12 22 23 25 2 12 9 5 1 13 24 6 16 10 1 14 3 25 12 15 Columns 31 through 60 7 4 6 21 1 12 14 4 25 23 20 4 1 25 14 14 6 26 18 18 26 22 26 17 9 8 26 12 10 13 Columns 61 through 90 19 8 9 12 14 15 21 15 13 5 5 14 7 7 23 23 21 23 22 21 4 4 3 22 22 10 7 17 17 13 Columns 91 through 120 12 12 5 25 25 6 12 11 16 5 17 10 19 13 26 11 15 14 23 21 5 24 15 22 11 22 1 3 10 14 Columns 121 through 150 26 13 9 2 7 22 25 4 11 7 22 9 25 19 18 14 15 19 8 7 15 17 3 5 19 5 5 7 11 26 Columns 151 through 180 11 24 18 1 19 9 22 10 2 20 2 14 22 2 20 14 24 18 24 1 10 23 4 17 7 17 18 18 26 10 Columns 181 through 210 21 15 18 9 13 17 15 1 12 5 1 6 7 1 20 6 5 13 15 15 22 17 24 9 8 11 9 23 15 10 Columns 211 through 240 2 1 2 20 22 6 20 19 12 25 14 17 15 9 2 4 12 12 1 6 21 17 3 17 20 10 9 13 22 8 Columns 241 through 270 8 13 10 11 25 1 22 17 16 5 17 24 11 8 22 18 5 19 16 18 21 7 5 14 10 25 3 22 20 10 Columns 271 through 300 2 23 23 19 2 6 19 12 19 19 8 19 1 8 13 26 10 16 13 16 4 12 1 25 11 22 24 24 24 16 Columns 301 through 330 23 16 13 19 11 14 23 24 16 23 18 16 24 26 18 20 26 2 2 9 23 23 9 20 17 26 3 20 5 11 Columns 331 through 360 11 10 14 9 18 10 9 10 26 18 24 12 15 19 7 1 19 3 22 23 7 18 19 25 12 2 22 13 7 22

2   Pass
nocheat = isempty(regexp(evalc('type random_sequence'),'([^f]eval|regexprep|inline|str2func)')); m = 2; s = 1000; y = random_sequence(m,s); assert(isequal(sum(y),s) && abs(mean(y)-m/2)<m*sqrt(m/s)+1/2 && isequal(y,round(y)) && abs(std(y)-m/sqrt(12))*sqrt(s)/m<2.5 && nocheat)

y = Columns 1 through 30 1 2 1 1 1 1 2 1 2 2 2 1 1 2 1 1 1 1 2 2 2 2 1 2 1 1 2 2 1 2 Columns 31 through 60 1 1 1 2 2 1 1 2 2 1 1 1 2 1 2 1 1 1 1 1 1 1 2 1 1 1 2 1 2 2 Columns 61 through 90 1 2 1 1 2 1 2 1 1 2 1 2 2 1 2 2 1 1 2 2 1 2 1 1 1 2 1 2 1 1 Columns 91 through 120 1 1 2 1 2 1 2 2 2 1 1 2 2 2 2 2 1 1 2 2 2 1 1 1 1 2 2 1 2 1 Columns 121 through 150 2 2 2 1 1 1 1 2 2 2 2 1 1 1 1 1 1 2 1 1 1 1 2 1 2 2 1 1 1 1 Columns 151 through 180 1 1 1 1 1 2 2 2 2 1 2 2 2 1 2 2 1 2 1 1 1 1 1 1 2 1 2 1 2 2 Columns 181 through 210 1 2 1 2 1 1 2 1 2 2 2 1 2 1 2 1 1 2 1 1 1 1 1 2 1 1 1 2 1 1 Columns 211 through 240 1 2 1 1 2 1 2 2 1 1 2 2 2 2 1 2 1 2 2 1 2 2 2 1 2 1 1 1 2 1 Columns 241 through 270 2 2 2 2 2 1 1 2 2 2 2 2 1 2 1 2 2 1 1 1 1 1 2 2 2 1 2 1 2 2 Columns 271 through 300 2 2 1 2 2 2 2 1 2 2 2 1 1 1 1 2 1 1 1 1 2 2 2 2 1 2 2 1 1 2 Columns 301 through 330 2 2 1 1 1 1 1 2 1 1 2 1 2 1 2 1 2 1 2 1 1 1 1 1 2 1 2 2 1 1 Columns 331 through 360 1 2 2 1 2 2 2 2 1 1 1 1 1 1 1 1 1 2 2 2 1 2 1 2 1 2 2 2 2 2 Columns 361 through 390 2 1 1 2 2 1 2 2 1 2 1 1 2 1 2 2 2 2 2 2 2 1 1 2 1 1 2 2 1 2 Columns 391 through 420 2 1 2 2 1 1 2 1 2 2 2 2 1 1 2 1 1 2 2 2 2 2 2 1 1 1 2 1 1 2 Columns 421 through 450 1 2 2 1 1 1 2 1 1 1 1 1 1 2 1 2 1 1 1 1 1 1 1 2 1 2 1 2 1 2 Columns 451 through 480 2 1 2 2 1 2 1 2 2 1 2 1 1 2 2 1 2 2 2 2 1 1 1 1 1 1 1 2 1 2 Columns 481 through 510 1 1 1 1 2 1 2 2 1 1 1 1 1 1 1 1 2 2 1 2 2 2 2 2 1 1 2 2 1 1 Columns 511 through 540 1 1 1 2 1 2 1 2 1 1 1 1 2 1 2 2 1 2 1 2 2 1 1 2 2 2 1 2 1 1 Columns 541 through 570 1 1 1 1 1 1 1 2 1 2 2 1 1 2 1 1 2 1 2 2 2 2 2 2 1 1 2 1 1 2 Columns 571 through 600 1 1 1 1 1 2 2 2 2 2 1 2 2 1 2 1 1 2 2 1 1 1 1 1 1 1 2 1 2 1 Columns 601 through 630 2 2 2 2 1 1 2 2 2 2 1 1 2 2 1 1 1 1 2 2 2 1 1 1 1 2 2 1 1 2 Columns 631 through 660 1 1 2 2 2 2 2 1 2 1 1 2 2 2 1 2 1 1 2 1 2 2 2 2 1 2 1 2 1 1 Columns 661 through 682 1 1 2 2 1 1 1 1 2 1 1 1 2 2 2 1 1 1 1 2 2 1

3   Pass
nocheat = isempty(regexp(evalc('type random_sequence'),'([^f]eval|regexprep|inline|str2func)')); m = 1000; s = 100000; y = random_sequence(m,s); assert(isequal(sum(y),s) && abs(mean(y)-m/2)<m*sqrt(m/s)+1/2 && isequal(y,round(y)) && abs(std(y)-m/sqrt(12))*sqrt(s^1/m^3)<1 && nocheat)

y = Columns 1 through 30 336 74 66 521 986 517 55 690 544 156 549 427 353 64 907 270 959 776 174 836 702 845 296 524 911 865 783 146 126 405 Columns 31 through 60 551 445 560 661 219 699 903 934 941 436 612 379 376 681 653 992 819 487 364 84 213 275 601 321 537 373 928 251 263 374 Columns 61 through 90 741 346 224 78 947 39 900 380 574 587 108 448 128 547 639 470 762 713 768 173 273 629 487 778 123 755 601 75 231 626 Columns 91 through 120 850 694 496 754 464 222 138 758 833 559 386 314 632 620 29 546 219 75 829 23 492 704 111 555 507 484 107 959 235 536 Columns 121 through 150 331 901 780 22 232 687 616 805 628 415 819 151 597 393 64 127 859 202 402 947 69 402 502 601 722 794 123 885 100 133 Columns 151 through 180 738 809 49 559 675 865 370 221 472 557 456 59 908 678 258 546 855 489 114 618 15 984 597 137 169 918 453 486 120 872 Columns 181 through 203 786 99 682 129 551 77 827 286 375 944 984 836 29 557 505 108 998 812 208 248 167 815 545