Cody

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

Solution 1846179

Submitted on 11 Jun 2019 by Hans Kramer
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
x = 5; assert(isequal(unique(rand_plusminus1(x)),[-1;1]))

y = 0.9875 0.3499 0.9890 0.0399 0.6821 0.0098 0.6007 0.5473 0.1386 0.9275 0.4964 0.4861 0.3374 0.3832 0.6562 0.3931 0.0522 0.7201 0.2061 0.0018 0.7777 0.3459 0.8006 0.2508 0.8434 y = 1.0000 0.3499 1.0000 0.0399 1.0000 0.0098 1.0000 1.0000 0.1386 1.0000 0.4964 0.4861 0.3374 0.3832 1.0000 0.3931 0.0522 1.0000 0.2061 0.0018 1.0000 0.3459 1.0000 0.2508 1.0000 y = 1 -1 1 -1 1 -1 1 1 -1 1 -1 -1 -1 -1 1 -1 -1 1 -1 -1 1 -1 1 -1 1

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

y = 0.9729 y = 1 y = 1

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

y = [] y = [] y = []

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

y = Columns 1 through 18 0.5870 0.6763 0.0196 0.9384 0.0085 0.0329 0.9048 0.5427 0.3545 0.3651 0.3067 0.9673 0.9524 0.1550 0.6687 0.0950 0.9303 0.2785 0.7964 0.3211 0.4792 0.0905 0.6617 0.1344 0.9113 0.3201 0.3694 0.2515 0.7126 0.0009 0.6808 0.5693 0.3719 0.9264 0.9416 0.7521 0.6778 0.3159 0.5242 0.5883 0.7809 0.9569 0.7220 0.5190 0.8808 0.9624 0.7644 0.4549 0.0652 0.4605 0.9254 0.2379 0.0714 0.0425 0.3736 0.3752 0.2578 0.6377 0.6269 0.9230 0.9879 0.5357 0.6671 0.6637 0.2906 0.5128 0.5331 0.4936 0.4890 0.5529 0.1960 0.0994 0.4104 0.5770 0.4825 0.8932 0.7509 0.8009 0.7620 0.0923 0.1705 0.7431 0.7316 0.0064 0.4887 0.7068 0.1031 0.8960 0.6727 0.6759 0.6811 0.6106 0.0057 0.6822 0.9999 0.2786 0.6390 0.8655 0.2698 0.6363 0.7939 0.3781 0.0001 0.6583 0.0008 0.9406 0.3932 0.5857 0.2090 0.2371 0.9540 0.7132 0.5565 0.2956 0.8685 0.6003 0.6218 0.1567 0.0378 0.3006 0.3911 0.7973 0.2537 0.0144 0.3644 0.3451 0.2219 0.5596 0.7310 0.5401 0.9241 0.7165 0.8795 0.2724 0.6514 0.7700 0.5593 0.5572 0.7668 0.5338 0.4337 0.6955 0.6005 0.6360 0.8718 0.2097 0.1493 0.0462 0.7375 0.6836 0.5130 0.0421 0.6673 0.4093 0.9032 0.9160 0.6986 0.6886 0.0814 0.1980 0.3803 0.7945 0.7980 0.5185 0.7821 0.2527 0.6310 0.8236 0.3046 0.2972 0.3669 0.8256 0.6263 0.1752 0.3717 0.4276 0.3682 0.8521 0.6311 0.1477 0.5113 0.9852 0.6384 0.2586 0.4716 0.3444 0.2912 0.8208 0.3831 0.8182 0.3007 0.3245 0.8885 0.4454 0.7677 0.0339 0.4537 0.5869 0.0077 0.0599 0.3726 0.3422 0.7441 0.0327 0.0966 0.8392 0.2441 0.3030 0.0801 0.6341 0.5306 0.5449 0.3339 0.1894 0.4138 0.7413 0.2264 0.7484 0.1454 0.0424 0.3008 0.1582 0.1850 0.5075 0.9969 0.9147 0.8510 0.3696 0.6738 0.0836 0.7422 0.9445 0.9140 0.3900 0.1942 0.9305 0.0966 0.7388 0.6460 0.8022 0.8889 0.3346 0.5319 0.3697 0.9893 0.0164 0.2633 0.3079 0.0333 0.0892 0.1915 0.6159 0.2613 0.2344 0.8846 0.5843 0.6009 0.5228 0.0635 0.1300 0.7506 0.7587 0.7970 0.1857 0.7750 0.2260 0.9306 0.4775 0.4950 0.2448 0.8694 0.2354 0.7005 0.6144 0.7978 0.8212 0.6346 0.2702 0.5358 0.4933 0.6288 0.7900 0.4411 0.0312 0.3590 0.7712 0.0811 0.2943 0.6689 0.5892 0.6425 0.2273 0.6561 0.1847 0.4570 0.3283 0.5513 0.1466 0.5125 0.0367 0.2695 0.9932 0.2603 0.1735 0.6825 0.2411 0.8890 0.9368 0.2911 0.7285 0.8593 0.5999 0.0372 0.7611 0.8667 0.4176 0.7407 0.6444 0.0706 0.1973 0.4598 0.4911 0.8661 0.9823 0.6313 0.2138 0.2287 0.5618 0.9933 0.4465 0.8907 0.7465 0.7556 0.2795 0.7893 0.8667 0.9341 0.2921 0.3181 0.0411 0.3158 0.3180 0.4486 0.8515 0.3326 0.3766 0.8507 0.6180 0.7850 0.8006 0.0359 0.0174 0.2945 0.0831 0.0268 0.6886 0.3008 0.1627 0.0475 0.0956 0.6500 0.3698 0.7314 0.0725 0.9289 0.7072 0.4992 0.6192 0.5672 0.1372 0.3425 0.7932 0.8820 0.6896 0.7812 0.0575 0.3868 0.8720 0.5551 0.3895 0.6022 0.2108 0.5741 0.3178 0.2251 0.2657 0.5069 0.0160 0.7142 0.1904 0.4487 0.6214 0.6522 0.1566 0.8192 0.6235 0.9729 0.5634 0.1848 0.4164 0.0829 0.7874 0.3365 0.3481 0.7192 0.0304 0.0497 0.6878 0.8565 0.7921 0.1437 0.8245 0.9085 0.9684 0.5106 0.4921 0.7726 0.3387 0.9498 0.6167 0.2521 0.8459 0.8320 0.0336 0.5980 0.5817 0.0570 0.4272 0.7389 0.6182 0.2269 0.7154 0.9878 0.5001 0.2319 0.7019 0.6289 0.2005 0.0746 0.7160 0.8085 0.0542 0.8188 0.4657 0.0041 0.4943 0.4180 0.7434 0.7106 0.6073 0.3519 0.5233 0.7277 0.8592 0.5381 0.7712 0.1517 0.1243 0.9819 0.4073 0.4646 0.2393 0.7184 0.0926 0.4936 0.6528 0.8282 0.6144 0.6726 0.7520 0.2599 0.6167 0.8661 0.5134 0.8945 0.5292 0.3606 0.3915 0.8609 0.9335 0.9883 0.0709 0.4041 0.9012 0.3644 0.1889 0.4430 0.7419 0.9780 0.6272 0.5813 0.0754 0.0764 0.3995 0.5025 0.7174 0.2947 0.1720 0.0014 0.5086 0.8317 0.8005 0.8098 0.3626 0.8205 0.9181 0.0075 0.7539 0.2832 0.8927 0.6754 0.5585 0.1999 0.1937 0.5961 0.8296 0.2464 0.2381 0.1303 0.7577 0.6304 0.9280 0.7426 0.7005 0.2825 0.5051 0.3404 0.9739 0.5259 0.2913 0.2619 0.8022 0.4687 0.9066 0.1242 0.2875 0.9023 0.3222 0.6450 0.9020 0.0708 0.0254 0.4606 0.0374 0.6287 0.6216 0.5475 0.3184 0.5939 0.0832 0.8330 0.9032 0.9282 0.5341 0.5148 0.9385 0.9618 0.8032 0.7875 0.5217 0.3139 0.1954 0.4031 0.0523 0.1736 0.0971 0.5625 0.0084 0.8826 0.1598 0.0280 0.1190 0.6560 0.3992 0.4140 0.2878 0.9281 0.8270 0.1810 0.5362 0.8738 0.7461 0.6536 0.5299 0.6321 0.2008 0.7424 0.6372 0.5527 0.0016 0.9288 0.1945 0.9023 0.4844 0.2440 0.1923 0.1077 0.8739 0.2190 0.6844 0.4998 0.9001 0.9354 0.2871 0.2690 0.2310 0.3256 0.0967 0.7172 0.6753 0.7297 0.9961 0.5988 0.5320 0.8309 0.7239 0.8113 0.5891 0.5208 0.9479 0.9337 0.8483 0.4882 0.3759 0.3484 0.3953 0.4771 0.0035 0.8782 0.2874 0.2851 0.4943 0.0435 0.8264 0.4320 0.9298 0.7212 0.0670 0.8807 0.1858 0.6983 0.0124 0.5413 0.0644 0.3321 0.0678 0.0684 0.6597 0.9657 0.4314 0.3478 0.3941 0.6894 0.4322 0.1009 0.6647 0.1000 0.9287 0.4452 0.8853 0.2735 0.2378 0.7962 0.0710 0.1704 0.2497 0.8844 0.5108 0.5283 0.1901 0.3738 0.1142 0.2671 0.1806 0.9789 0.2555 0.4681 0.0380 0.5688 0.5688 0.2274 0.9198 0.6003 0.8275 0.6908 0.3337 0.9169 0.3527 0.1912 0.8751 0.2181 0.0957 0.8480 0.5558 0.8852 0.5119 0.9545 0.7004 0.9529 0.1299 0.3106 0.7464 0.6652 0.0199 0.2486 0.9073 0.1163 0.6776 0.6573 0.2007 0.2928 0.4553 0.9497 0.8073 0.0060 0.1052 0.6951 0.4381 0.7172 0.3196 0.9602 0.5004 0.5041 0.8287 0.9905 0.0793 0.2983 0.1691 0.5565 0.5605 0.2869 0.4062 0.7953 0.7695 0.3430 0.4667 0.5801 0.1805 0.5637 0.6315 0.9435 0.1101 0.7235 0.8660 0.3846 0.6137 0.7234 0.9743 0.7687 0.9572 0.9124 0.5627 0.5759 0.4498 0.4637 0.3169 0.7571 0.9338 0.8630 0.2440 0.9757 0.5643 0.1114 0.5148 0.2735 0.6793 0.3262 0.2008 0.4183 0.5198 0.5248 0.7179 0.7420 0.0939 0.5460 0.3696 0.0797 0.0015 0.5095 0.3066 0.9616 0.3316 0.5049 0.9104 0.1522 0.8015 0.7829 0.4485 0.7125 0.5291 0.6632 0.3087 0.3323 0.0751 0.6295 0.5300 0.6438 0.9189 0.8769 0.0606 0.9958 0.4625 0.1984 0.7168 0.5721 0.7214 0.6634 0.9298 0.7439 0.0170 0.9960 0.1937 0.1146 0.1686 0.7565 0.1950 0.3581 0.7063 0.5143 0.1957 0.4471 0.4729 0.2321 0.3846 0.4517 0.7272 0.2351 0.3508 0.0972 0.3434 0.0444 0.4923 0.4747 0.6838 0.4083 0.3620 0.6777 0.0205 0.3526 0.7775 0.8525 0.2330 0.3341 0.9447 0.3741 0.9038 0.4627 0.1979 0.0499 0.1591 0.0807 0.5575 0.5031 0.1212 0.7143 0.5383 0.6908 0.8365 0.8669 0.1494 0.2397 0.5882 0.1393 0.6327 0.4116 0.6172 0.7952 0.7002 0.6277 0.4819 0.8503 0.9169 0.3964 0.9883 0.9747 0.4059 0.8489 0.6736 0.9623 0.8048 0.5786 0.3038 0.9048 0.6500 0.9185 0.8522 0.1996 0.4380 0.4131 0.6254 0.6057 0.4879 0.2722 0.1145 0.0172 0.3717 0.3153 0.0630 0.6403 0.3968 0.5968 0.1699 0.5205 0.3240 0.1299 0.0014 0.7638 0.7529 0.7885 0.3059 0.1587 0.4358 0.0272 0.2049 0.1704 0.5695 0.9762 0.2972 0.0543 0.4412 0.3007 0.5112 0.5051 0.6931 0.9550 0.5343 0.6535 0.3434 0.5254 0.3676 0.6559 0.6531 0.2342 0.8128 0.7817 0.9602 0.5973 0.6038 0.6585 0.9956 0.8745 0.9123 0.1834 0.8989 0.6553 0.1271 0.8068 0.0890 0.6914 0.3316 0.8072 0.0303 0.0587 0.8350 0.6413 0.4395 0.6064 0.7291 0.4932 0.2505 0.2709 0.8290 0.7583 0.6673 0.3889 0.7526 0.8198 0.7329 0.3859 0.0598 0.5077 0.2186 0.2046 0.7616 0.8998 0.5514 0.3331 0.3122 0.9252 0.2069 0.5260 0.8381 0.7529 0.6731 0.6718 0.6978 0.8653 0.2387 0.9677 0.2938 0.0949 0....