Cody

# Problem 1998. Bleed non-zeros to the right

Solution 1962360

Submitted on 6 Oct 2019 by Augusto Mazzei
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 = [1 0 0 2 0]; y_correct = [1 1 1 2 2]; assert(isequal(bleed_to_the_right(x),y_correct)) filetext = fileread('bleed_to_the_right.m'); assert(isempty(strfind(filetext, 'regexp')),'regexp* command is forbidden') assert(isempty(strfind(filetext, 'eval')),'eval* command is forbidden') assert(isempty(strfind(filetext, 'inline')),'inline command is forbidden')

ans = 1 1 1 2 2

2   Pass
x = [0 0 -12 13 0 i 0 -i 76.54321 0 0]; y_correct = [0 0 -12 13 13 i i -i 76.54321 76.54321 76.54321]; assert(isequal(bleed_to_the_right(x),y_correct))

ans = Columns 1 through 9 0.0000 + 0.0000i 0.0000 + 0.0000i -12.0000 + 0.0000i 13.0000 + 0.0000i 13.0000 + 0.0000i 0.0000 + 1.0000i 0.0000 + 1.0000i 0.0000 - 1.0000i 76.5432 + 0.0000i Columns 10 through 11 76.5432 + 0.0000i 76.5432 + 0.0000i

3   Pass
x = [1:100 0]; y_correct = [1:100 100]; assert(isequal(bleed_to_the_right(x),y_correct))

ans = Columns 1 through 30 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 Columns 31 through 60 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 Columns 61 through 90 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 Columns 91 through 101 91 92 93 94 95 96 97 98 99 100 100

4   Pass
x = rand(1,1000); x(randi(500,1,50)*2) = 0; y_correct = x; y_correct(~y_correct) = y_correct(find(~y_correct)-1); assert(isequal(bleed_to_the_right(x),y_correct))

ans = Columns 1 through 18 0.4794 0.1887 0.6513 0.4849 0.4141 0.3364 0.0815 0.0296 0.5742 0.9998 0.0423 0.5165 0.2700 0.2700 0.3833 0.2834 0.6325 0.5041 Columns 19 through 36 0.3891 0.1356 0.1100 0.2627 0.6412 0.4463 0.2893 0.6914 0.2928 0.7380 0.5955 0.2854 0.2990 0.2582 0.4085 0.8683 0.5233 0.4637 Columns 37 through 54 0.9820 0.3339 0.1408 0.1408 0.5318 0.7673 0.7529 0.1578 0.1904 0.4494 0.0242 0.4912 0.8393 0.5099 0.3241 0.1870 0.3887 0.3887 Columns 55 through 72 0.9043 0.9043 0.8094 0.5983 0.0379 0.9375 0.3599 0.1236 0.2410 0.0020 0.0617 0.2992 0.9160 0.5124 0.0233 0.5721 0.1390 0.2433 Columns 73 through 90 0.9980 0.9603 0.1733 0.1388 0.8430 0.2290 0.6277 0.6277 0.5051 0.0338 0.4020 0.5293 0.3428 0.6259 0.6891 0.8157 0.7654 0.1647 Columns 91 through 108 0.5327 0.3551 0.9256 0.6862 0.1918 0.6167 0.1549 0.4161 0.3674 0.4361 0.6810 0.3052 0.4175 0.0275 0.6464 0.9715 0.7432 0.1871 Columns 109 through 126 0.1578 0.2661 0.7933 0.8860 0.3793 0.9918 0.4081 0.4081 0.1223 0.6860 0.4456 0.9921 0.4881 0.9448 0.6041 0.2436 0.7896 0.5194 Columns 127 through 144 0.5133 0.3983 0.4051 0.7623 0.3470 0.6958 0.8323 0.4114 0.9150 0.4250 0.3541 0.9692 0.6654 0.9693 0.1506 0.4353 0.2643 0.6839 Columns 145 through 162 0.5465 0.7474 0.1040 0.2632 0.4557 0.5817 0.7393 0.7393 0.5519 0.5164 0.7628 0.7987 0.9048 0.9430 0.0972 0.4072 0.2903 0.7155 Columns 163 through 180 0.2882 0.2394 0.4903 0.7210 0.4127 0.9614 0.9836 0.7701 0.1311 0.9919 0.5708 0.8762 0.0527 0.4079 0.0406 0.9620 0.2795 0.4545 Columns 181 through 198 0.2530 0.6166 0.0651 0.0471 0.8355 0.0417 0.5373 0.1708 0.7306 0.5272 0.0539 0.6380 0.2769 0.0937 0.5144 0.5144 0.0205 0.4262 Columns 199 through 216 0.0987 0.4244 0.8340 0.9656 0.5639 0.5837 0.0281 0.7162 0.6909 0.7272 0.0092 0.1677 0.2757 0.9822 0.0184 0.8692 0.3473 0.2692 Columns 217 through 234 0.4533 0.8667 0.1957 0.8875 0.7900 0.7900 0.4920 0.1499 0.7275 0.5747 0.2521 0.3979 0.6699 0.2035 0.7592 0.6899 0.9905 0.2891 Columns 235 through 252 0.3947 0.3364 0.4641 0.1131 0.1668 0.0659 0.0413 0.0413 0.0539 0.3639 0.7273 0.0493 0.4368 0.9181 0.0822 0.9177 0.6604 0.8338 Columns 253 through 270 0.6050 0.6277 0.2561 0.3108 0.1792 0.5206 0.8962 0.8962 0.2485 0.5554 0.8358 0.8710 0.9518 0.2838 0.0785 0.7410 0.2687 0.7721 Columns 271 through 288 0.9967 0.9967 0.6472 0.5183 0.9967 0.9967 0.1222 0.2587 0.1139 0.8907 0.5498 0.5498 0.5046 0.8527 0.3431 0.4528 0.4105 0.9701 Columns 289 through 306 0.4408 0.6481 0.6044 0.5865 0.5190 0.9944 0.2921 0.2921 0.0135 0.0458 0.4152 0.8942 0.7638 0.8859 0.7483 0.6562 0.3291 0.2140 Columns 307 through 324 0.3854 0.9691 0.8232 0.0253 0.8569 0.3831 0.6643 0.4699 0.6138 0.2137 0.5277 0.8836 0.8212 0.8236 0.8218 0.8419 0.0156 0.5043 Columns 325 through 342 0.5135 0.0966 0.2756 0.0476 0.2734 0.1738 0.7865 0.0773 0.7338 0.7015 0.6052 0.6052 0.6787 0.6499 0.5132 0.4465 0.2684 0.3734 Columns 343 through 360 0.3333 0.3587 0.4091 0.8222 0.2131 0.2283 0.1224 0.8892 0.8301 0.3807 0.7672 0.1876 0.6223 0.4269 0.9405 0.0579 0.4995 0.1005 Columns 361 through 378 0.3632 0.1764 0.9498 0.6058 0.7348 0.2076 0.4640 0.3139 0.7279 0.8918 0.1297 0.0763 0.8101 0.6218 0.2805 0.0727 0.5535 0.5725 Columns 379 through 396 0.3159 0.9624 0.0885 0.3252 0.3346 0.9284 0.2312 0.8687 0.9448 0.6732 0.0212 0.7417 0.9299 0.8990 0.8909 0.0647 0.9582 0.9582 Columns 397 through 414 0.1315 0.2949 0.9067 0.0351 0.0283 0.9143 0.9601 0.7635 0.8969 0.3062 0.9430 0.7201 0.1686 0.0434 0.8411 0.4995 0.3177 0.8357 Columns 415 through 432 0.7149 0.7926 0.7016 0.7190 0.4981 0.4470 0.4722 0.5819 0.1351 0.2843 0.3265 0.5858 0.5300 0.8950 0.8123 0.3183 0.9838 0.9838 Columns 433 through 450 0.8511 0.0742 0.7152 0.3549 0.9260 0.4507 0.4882 0.8503 0.0365 0.7874 0.7897 0.9238 0.7409 0.9521 0.9756 0.1114 0.0237 0.6146 Columns 451 through 468 0.4594 0.7374 0.4640 0.6343 0.6371 0.7474 0.0271 0.0271 0.4273 0.1831 0.0054 0.3704 0.9541 0.2017 0.9645 0.3115 0.0968 0.6696 Columns 469 through 486 0.0370 0.9911 0.6066 0.6066 0.6576 0.3569 0.6071 0.9077 0.8687 0.3578 0.7608 0.7608 0.0949 0.2568 0.4510 0.3367 0.1458 0.1186 Columns 487 through 504 0.2105 0.5704 0.7332 0.7204 0.0136 0.6358 0.5689 0.7965 0.5200 0.9471 0.5311 0.7008 0.2642 0.2390 0.6254 0.6254 0.9736 0.9607 Columns 505 through 522 0.1351 0.9418 0.3792 0.7071 0.9755 0.9893 0.9682 0.9952 0.9583 0.2811 0.9959 0.7533 0.7022 0.7286 0.1966 0.7227 0.4693 0.7704 Columns 523 through 540 0.2953 0.9835 0.3407 0.4733 0.0399 0.6269 0.7207 0.4304 0.8836 0.5767 0.7977 0.7490 0.6316 0.2618 0.0920 0.8392 0.7937 0.5975 Columns 541 through 558 0.8827 0.3794 0.5297 0.2279 0.6025 0.0964 0.1742 0.6610 0.4770 0.8513 0.7960 0.1348 0.8622 0.7333 0.6495 0.6495 0.4385 0.1061 Columns 559 through 576 0.9148 0.4806 0.6712 0.6630 0.6169 0.8388 0.1821 0.1821 0.7656 0.8383 0.7039 0.2880 0.0167 0.3684 0.6513 0.4679 0.4698 0.0135 Columns 577 through 594 0.6090 0.9397 0.0457 0.0457 0.8498 0.8458 0.6357 0.4200 0.4294 0.8889 0.9060 0.5692 0.4960 0.3825 0.4327 0.0367 0.2089 0.3780 Columns 595 through 612 0.8934 0.0540 0.8480 0.8264 0.8185 0.6071 0.5303 0.5165 0.6357 0.6357 0.7239 0.4146 0.9093 0.4646 0.3326 0.2250 0.1228 0.3458 Columns 613 through 630 0.6467 0.6467 0.7734 0.3964 0.5517 0.0147 0.9873 0.2830 0.0841 0.1472 0.7338 0.4608 0.2570 0.9136 0.6783 0.6674 0.7773 0.9247 Columns 631 through 648 0.5174 0.3659 0.4124 0.5991 0.0690 0.0672 0.4689 0.9405 0.9786 0.2431 0.9307 0.0503 0.5148 0.9249 0.5888 0.4959 0.9492 0.3546 Columns 649 through 666 0.3582 0.7301 0.2904 0.2904 0.1021 0.1021 0.6562 0.0529 0.5298 0.0206 0.2218 0.7551 0.2446 0.8739 0.9210 0.7452 0.2540 0.3709 Columns 667 through 684 0.0150 0.0215 0.7153 0.7153 0.5054 0.9748 0.7248 0.6081 0.9858 0.1010 0.4046 0.8484 0.3970 0.8069 0.8806 0.1264 0.1709 0.7967 Columns 685 through 702 0.2439 0.1291 0.0285 0.4950 0.7795 0.6207 0.0230 0.6723 0.0074 0.6450 0.0127 0.0127 0.3808 0.6874 0.9699 0.4691 0.7301 0.7556 Columns 703 through 720 0.1859 0.0766 0.4661 0.4661 0.2413 0.1027 0.4720 0.4080 0.3437 0.4214 0.8458 0.1638 0.3012 0.6099 0.5138 0.7644 0.6460 0.6227 Columns 721 through 738 0.4680 0.4680 0.9174 0.0759 0.6625 0.8218 0.6555 0.3606 0.5931 0.9777 0.5555 0.2536 0.6298 0.3678 0.4042 0.7016 0.4261 0.4885 Columns 739 through 756 0.4271 0.0884 0.6821 0.5962 0.5891 0.4343 0.9548 0.6917 0.4375 0.1222 0.7802 0.4665 0.5241 0.8395 0.9717 0.7342 0.8150 0.9572 Columns 757 through 774 0.9623 0.9141 0.8627 0.5341 0.5327 0.5327 0.2820 0.5786 0.0100 0.7502 0.0427 0.0427 0.1311 0.0129 0.0230 0.5151 0.0146 0.2833 Columns 775 through 792 0.1930 0.9631 0.1810 0.8742 0.2812 0.4506 0.7243 0.5016 0.7448 0.3739 0.5604 0.2345 0.8510 0.5371 0.0174 0.7304 0.1829 0.6350 Columns 793 through 810 0.0396 0.9096 0.6121 0.7472 0.0127 0.7415 0.9914 0.3067 0.7815 0.7815 0.3409 0.6110 0.7604 0.2309 0.5365 0.7281 0.4133 0.5263 Columns 811 through 828 0.7972 0.9536 0.0270 0.2057 0.6624 0.7485 0.4126 0.7463 0.9238 0.0292 0.3811 0.9738 0.6522 0.7446 0.9836 0.1225 0.4220 0.9818 Columns 829 through 846 0.0753 0.4183 0.7315 0.0390 0.8985 0.4103 0.7699 0.3456 0.3500 0.4250 0.2388 0.8726 0.0400 0.1064 0.6457 0.7893 0.7293 0.1354 Columns 847 through 864 0.0347 0.0347 0.2401 0.5143 0.3243 0.3243 0.8751 0.2413 0.2930 0.3252 0.8451 0.5132 0.1435 0.8817 0.5473 0...

5   Pass
x = sqrt(1:100); y_correct = floor(x); x(x~=floor(x)) = 0; assert(isequal(bleed_to_the_right(x),y_correct))

ans = Columns 1 through 30 1 1 1 2 2 2 2 2 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 Columns 31 through 60 5 5 5 5 5 6 6 6 6 6 6 6 6 6 6 6 6 6 7 7 7 7 7 7 7 7 7 7 7 7 Columns 61 through 90 7 7 7 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 9 9 9 9 9 9 9 9 9 9 Columns 91 through 100 9 9 9 9 9 9 9 9 9 10