Cody

Problem 1227. Generate a random matrix A of (1,-1)

Solution 1813148

Submitted on 12 May 2019
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
x = 5; assert(isequal(unique(rand_plusminus1(x)),[-1;1]))

y = -1 -1 1 0 0

Assertion failed.

2   Pass
x = 1; assert(isequal(abs(rand_plusminus1(x)),1))

y = -1

3   Pass
x = 0; assert(isequal(rand_plusminus1(x),[]))

y = []

4   Fail
x = 999; assert(isequal(unique(rand_plusminus1(x)),[-1;1]))

y = Columns 1 through 29 1 1 0 1 0 -1 0 1 0 0 1 1 -1 1 0 1 -1 1 0 0 1 1 -1 0 1 0 -1 1 0 Columns 30 through 58 -1 0 -1 0 0 0 0 -1 0 1 -1 0 -1 1 1 0 -1 0 0 1 -1 -1 0 1 1 1 1 0 1 Columns 59 through 87 -1 -1 0 1 -1 -1 -1 1 0 1 0 1 -1 0 0 0 0 0 1 -1 -1 0 -1 -1 0 -1 0 -1 0 Columns 88 through 116 0 1 0 0 1 -1 0 1 1 0 1 0 -1 0 0 0 0 0 -1 1 1 -1 0 -1 1 1 1 0 -1 Columns 117 through 145 -1 -1 -1 0 1 1 -1 1 -1 -1 0 1 -1 0 -1 -1 0 1 0 0 -1 1 -1 0 1 0 0 -1 0 Columns 146 through 174 1 -1 -1 1 -1 0 -1 1 1 0 -1 -1 -1 1 -1 0 1 0 0 0 1 1 -1 -1 -1 -1 0 0 -1 Columns 175 through 203 1 0 -1 0 -1 1 0 1 -1 -1 -1 -1 1 -1 -1 1 -1 -1 0 -1 -1 0 1 0 0 1 -1 -1 0 Columns 204 through 232 0 1 0 0 0 -1 1 -1 1 -1 1 1 0 -1 0 1 1 0 1 -1 1 0 1 0 -1 1 -1 1 -1 Columns 233 through 261 -1 1 -1 0 -1 0 -1 0 1 0 0 0 -1 1 0 0 0 0 -1 0 1 1 -1 1 -1 0 -1 -1 1 Columns 262 through 290 -1 0 1 1 0 1 1 1 1 1 -1 1 0 1 -1 0 -1 1 0 1 0 -1 0 1 0 -1 1 -1 1 Columns 291 through 319 1 -1 -1 0 0 1 1 1 0 0 0 0 1 1 1 0 1 1 0 -1 -1 1 -1 -1 0 -1 0 1 -1 Columns 320 through 348 -1 0 -1 1 1 0 0 0 0 1 0 -1 1 0 0 1 1 0 0 0 -1 1 0 1 1 -1 1 1 -1 Columns 349 through 377 1 1 0 1 1 1 1 -1 -1 -1 1 -1 -1 -1 -1 0 0 1 1 0 -1 0 0 1 -1 -1 1 1 1 Columns 378 through 406 -1 0 1 0 1 -1 -1 0 -1 1 -1 -1 1 -1 0 0 0 1 0 1 1 1 1 1 -1 -1 -1 1 0 Columns 407 through 435 0 0 1 -1 1 -1 -1 0 1 -1 0 1 0 -1 1 1 -1 0 0 0 -1 -1 1 -1 1 -1 0 -1 1 Columns 436 through 464 1 1 1 -1 1 1 1 0 0 0 -1 -1 1 1 -1 0 0 -1 0 1 1 -1 1 0 0 0 1 0 1 Columns 465 through 493 1 1 -1 -1 0 1 0 -1 -1 -1 -1 1 -1 -1 -1 0 0 -1 0 0 0 0 1 0 1 1 1 1 1 Columns 494 through 522 -1 -1 -1 0 1 1 -1 -1 1 1 0 0 -1 0 0 -1 1 1 1 1 0 -1 1 0 -1 0 -1 -1 0 Columns 523 through 551 1 0 1 1 -1 0 -1 0 1 -1 -1 1 -1 1 -1 0 0 1 -1 -1 -1 1 1 -1 -1 1 -1 1 0 Columns 552 through 580 0 1 1 0 0 1 -1 0 -1 0 1 0 -1 -1 0 -1 0 1 0 0 0 -1 0 1 0 -1 1 0 -1 Columns 581 through 609 1 0 -1 -1 1 0 -1 -1 0 1 -1 1 -1 1 -1 -1 -1 1 0 1 1 -1 0 -1 1 1 0 -1 0 Columns 610 through 638 1 1 1 1 1 -1 1 -1 -1 -1 -1 0 0 -1 1 0 -1 0 0 -1 1 1 -1 1 1 0 -1 1 0 Columns 639 through 667 -1 0 0 -1 1 0 -1 -1 -1 1 0 0 1 0 0 1 1 1 0 0 -1 -1 1 0 -1 0 0 -1 -1 Columns 668 through 696 0 -1 1 0 1 0 1 0 1 1 -1 1 0 -1 -1 0 -1 0 1 -1 1 1 0 -1 1 1 1 -1 -1 Columns 697 through 725 1 -1 0 -1 1 1 -1 0 1 1 -1 -1 1 0 1 0 1 0 -1 0 -1 -1 -1 1 -1 1 0 0 -1 Columns 726 through 754 1 1 1 0 -1 0 -1 -1 -1 0 0 -1 1 0 1 0 -1 1 -1 1 0 0 0 1 -1 -1 1 1 -1 Columns 755 through 783 0 1 0 -1 1 0 -1 -1 1 1 1 1 -1 0 0 0 1 1 0 -1 0 1 -1 -1 0 -1 1 0 -1 Columns 784 through 812 0 -1 0 0 0 -1 1 1 -1 -1 1 0 -1 0 0 0 0 -1 1 0 0 -1 0 0 0 0 1 1 0 Columns 813 through 841 0 1 -1 -1 1 0 0 -1 1 -1 0 1 0 0 1 -1 -1 1 0 1 1 0 1 -1 1 1 0 -1 -1 Columns 842 through 870 1 1 -1 1 1 0 0 1 0 0 1 1 1 1 1 1 -1 0 -1 -1 1 1 0 1 0 -1 -1 -1 1 Columns 871 through 899 1 0 -1 -1 0 -1 -1 -1 0 0 -1 0 0 0 -1 -1 -1 0 0 1 0 -1 0 0 0 1 -1 1 -1 Columns 900 through 928 0 0 -1 0 1 0 -1 1 1 1 1 0 -1 -1 -1 0 0 1 0 1 1 1 1 1 0 -1 0 1 -1 Columns 929 through 957 0 1 -1 0 1 1 0 1 -1 0 0 -1 0 0 1 0 0 0 0 -1 1 -1 -1 -1 -1 0 1 0 -1 Columns 958 through 986 1 0 -1 1 0 -1 0 0 1 0 0 0 1 -1 1 0 1 0 0 1 -1 1 1 0 -1 -1 -1 -1 1 Columns 987 through 999 0 0 -1 -1 1 0 -1 -1 -1 -1 -1 0 -1

Assertion failed.