Cody

# Problem 1998. Bleed non-zeros to the right

Solution 2625532

Submitted on 28 Jun 2020 by Ebrahim Mahmoud
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')

a = 1 1 0 2 0 a = 1 1 1 2 0 a = 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))

a = Columns 1 through 9 0.0000 + 0.0000i 0.0000 + 0.0000i -12.0000 + 0.0000i 13.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 1.0000i 0.0000 + 0.0000i 0.0000 - 1.0000i 76.5432 + 0.0000i Columns 10 through 11 0.0000 + 0.0000i 0.0000 + 0.0000i a = 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 + 0.0000i 0.0000 - 1.0000i 76.5432 + 0.0000i Columns 10 through 11 0.0000 + 0.0000i 0.0000 + 0.0000i a = 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 0.0000 + 0.0000i 0.0000 + 0.0000i a = 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 0.0000 + 0.0000i a = 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))

a = 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))

a = Columns 1 through 18 0.2834 0.9821 0.8659 0.4023 0.8867 0.0514 0.1853 0.6892 0.5067 0.1242 0.1648 0.5727 0.7530 0.0950 0.6959 0.6959 0.7495 0.6862 Columns 19 through 36 0.6886 0 0.5346 0.7181 0.2502 0.9457 0.4686 0.6866 0.6542 0.0512 0.8278 0.4347 0.0350 0.2455 0.4821 0.4775 0.1658 0.7050 Columns 37 through 54 0.3022 0.6285 0.8430 0.7394 0.6455 0 0.4507 0.6638 0.2035 0.0890 0.4740 0.9225 0.2995 0.5830 0.9998 0.4994 0.5666 0.8722 Columns 55 through 72 0.2968 0.2770 0.5135 0.7015 0.6836 0.7428 0.2232 0.9844 0.4235 0.3774 0.5674 0.3400 0.0753 0.3792 0.7275 0.2868 0.7348 0.4334 Columns 73 through 90 0.6402 0.1747 0.0160 0.1995 0.7591 0.1531 0.5793 0.7813 0.1505 0.7076 0.6462 0.6533 0.7273 0 0.0824 0.4726 0.9955 0.6008 Columns 91 through 108 0.1513 0.9661 0.1865 0.0221 0.5692 0.6476 0.2365 0.6429 0.7808 0 0.5360 0.5386 0.1210 0.5166 0.9111 0.5125 0.3301 0.6225 Columns 109 through 126 0.9354 0 0.2757 0 0.0382 0 0.6553 0.7748 0.8266 0.6112 0.8547 0.2625 0.1519 0.4153 0.9753 0.6449 0.4978 0.1176 Columns 127 through 144 0.4471 0.2750 0.9487 0.2682 0.9077 0.0460 0.9064 0.3597 0.4220 0.3766 0.0929 0.4246 0.6608 0.0946 0.1420 0.7969 0.9530 0 Columns 145 through 162 0.0298 0.4502 0.7052 0.7216 0.6398 0.5224 0.8906 0.4025 0.3960 0.2520 0.2345 0.9509 0.7084 0.3176 0.3167 0 0.8931 0.5127 Columns 163 through 180 0.0537 0.9371 0.5282 0.3474 0.5011 0.1848 0.6396 0.6985 0.9649 0.2633 0.8299 0.9617 0.6345 0 0.7948 0.6465 0.4645 0.6173 Columns 181 through 198 0.4759 0 0.5547 0.2294 0.1880 0.8839 0.8528 0.2621 0.3700 0.1681 0.7628 0.4250 0.0141 0.7033 0.9726 0.5252 0.4003 0.2910 Columns 199 through 216 0.6027 0.2791 0.5972 0.9551 0.3937 0.2578 0.7032 0.3545 0.2117 0.0137 0.7880 0.7436 0.6323 0.5713 0.8341 0.4390 0.6502 0.1288 Columns 217 through 234 0.4208 0.0207 0.1732 0 0.5567 0.3180 0.0619 0.1284 0.1059 0.8658 0.6048 0.6920 0.8073 0.6375 0.9229 0.0783 0.3336 0.3197 Columns 235 through 252 0.8610 0.5603 0.4085 0.2858 0.4720 0.6989 0.6612 0.1228 0.9687 0.1581 0.6855 0.6481 0.8937 0.0614 0.6746 0.6486 0.8481 0.9361 Columns 253 through 270 0.8817 0.7080 0.3895 0.9441 0.6646 0.8767 0.4986 0.7525 0.0309 0.4802 0.9946 0.8729 0.8997 0.3903 0.6749 0.3244 0.6014 0 Columns 271 through 288 0.5280 0.6290 0.1601 0.3539 0.1867 0.9050 0.0266 0.4749 0.6316 0.6344 0.0752 0.7535 0.2962 0.2103 0.3969 0.1004 0.3794 0.2182 Columns 289 through 306 0.2826 0.4742 0.0875 0.6736 0.9451 0.3889 0.4634 0.2650 0.1964 0 0.4994 0.7996 0.6995 0.7417 0.8335 0.3378 0.5782 0.5150 Columns 307 through 324 0.5461 0.0036 0.1839 0.4878 0.7696 0.4434 0.1124 0.7522 0.9904 0.8063 0.9912 0.9908 0.7731 0.8408 0.1015 0.3883 0.5253 0.4947 Columns 325 through 342 0.9147 0.1050 0.8897 0.9741 0.5686 0.0942 0.3023 0.9297 0.4322 0.0107 0.8271 0.4947 0.3553 0.9581 0.2555 0.0650 0.2253 0.6799 Columns 343 through 360 0.2463 0.1208 0.4036 0.9945 0.2242 0.5149 0.7270 0.3271 0.3058 0.4515 0.1323 0.9976 0.6738 0.0474 0.1134 0.7249 0.5507 0.9087 Columns 361 through 378 0.5329 0.4102 0.0810 0 0.5939 0.0505 0.6062 0.2453 0.8626 0.7227 0.2019 0 0.5850 0.2923 0.7997 0.4517 0.1719 0.3004 Columns 379 through 396 0.5705 0.2777 0.3667 0.9711 0.7741 0.1978 0.4323 0.2012 0.0503 0.3840 0.6897 0.5048 0.5275 0.1556 0.6164 0.3246 0.8929 0.4206 Columns 397 through 414 0.5605 0.8751 0.5037 0.0260 0.9446 0.0863 0.5318 0.8679 0.0463 0.8716 0.2812 0.4463 0.7337 0 0.2542 0.8263 0.5117 0.4928 Columns 415 through 432 0.8569 0 0.9488 0 0.8440 0 0.6391 0.6271 0.4084 0.0020 0.0744 0.0010 0.7601 0 0.4111 0.2959 0.0423 0.3056 Columns 433 through 450 0.1051 0.4719 0.5569 0.7559 0.9891 0 0.2102 0.3406 0.1336 0.7791 0.1709 0.6042 0.3820 0.6850 0.0348 0.3645 0.6494 0.4462 Columns 451 through 468 0.6271 0.9912 0.6905 0.3988 0.5859 0.4646 0.7392 0.0013 0.0162 0.6832 0.2377 0 0.4063 0.6038 0.9290 0.1199 0.9912 0.8123 Columns 469 through 486 0.4593 0 0.9040 0.6197 0.0133 0.8055 0.3568 0.5091 0.9137 0.2310 0.6351 0.8536 0.5396 0.1561 0.8513 0.2452 0.9886 0.8676 Columns 487 through 504 0.3219 0 0.8590 0.3401 0.7553 0.1108 0.7128 0.7906 0.6870 0.9628 0.1067 0.3327 0.8818 0.5761 0.6428 0.4014 0.3076 0 Columns 505 through 522 0.9240 0.8483 0.7865 0.9200 0.3431 0.6736 0.4509 0.8320 0.4779 0.4379 0.2523 0.5588 0.8193 0.7035 0.9442 0.2476 0.3390 0.4684 Columns 523 through 540 0.2850 0.2664 0.0882 0 0.4806 0.9578 0.3879 0.3501 0.6320 0.6386 0.4491 0.8642 0.8067 0.2713 0.8445 0.9217 0.5639 0.4697 Columns 541 through 558 0.2944 0.4292 0.0045 0.2902 0.7283 0.9681 0.3135 0 0.1353 0.1103 0.4699 0.0722 0.1948 0.2436 0.1047 0.3649 0.0344 0.5876 Columns 559 through 576 0.4596 0.1542 0.2153 0.2713 0.9106 0 0.6955 0.5037 0.3788 0.9069 0.1914 0.7457 0.7393 0.0976 0.3238 0.6464 0.9217 0.0259 Columns 577 through 594 0.1882 0.0850 0.3990 0.0607 0.6573 0.0628 0.2169 0.6360 0.9739 0.5835 0.0778 0.8303 0.7051 0 0.1570 0.9700 0.5784 0.1063 Columns 595 through 612 0.9989 0.6228 0.9264 0.2755 0.4747 0.8605 0.2569 0.9073 0.3397 0.4623 0.5465 0.4172 0.8460 0.4190 0.9875 0.3529 0.1480 0.1289 Columns 613 through 630 0.4052 0.7799 0.3213 0 0.3065 0.6432 0.1917 0.8696 0.9538 0 0.8477 0.2957 0.3117 0.5096 0.6263 0.7664 0.2969 0.9735 Columns 631 through 648 0.8041 0.8490 0.8624 0.2121 0.5456 0.9585 0.0919 0.7106 0.0376 0.2212 0.1243 0.7834 0.7498 0.2159 0.7156 0.5512 0.3174 0.2280 Columns 649 through 666 0.1885 0.1611 0.9460 0.7294 0.3934 0.8443 0.5652 0.3895 0.7050 0 0.7596 0 0.8319 0.3114 0.7461 0 0.6123 0.3302 Columns 667 through 684 0.7168 0.1229 0.3358 0.6342 0.8700 0.7146 0.7366 0 0.9781 0.5974 0.9209 0.2731 0.6559 0.7841 0.0507 0.8312 0.7769 0.3939 Columns 685 through 702 0.2898 0.8798 0.7023 0.9552 0.6446 0.0505 0.1163 0 0.5695 0.4020 0.2984 0.1694 0.4103 0.1452 0.9464 0.3820 0.1079 0.7400 Columns 703 through 720 0.9627 0.1580 0.1229 0.5015 0.4514 0.0641 0.6966 0.4363 0.6078 0.0737 0.9746 0.5446 0.1025 0.2259 0.5006 0.3299 0.6040 0.6950 Columns 721 through 738 0.1374 0 0.9855 0.8989 0.1455 0.0362 0.6051 0.1822 0.8069 0.9783 0.0005 0.0403 0.2582 0.9434 0.9842 0.1809 0.0179 0.9376 Columns 739 through 756 0.4292 0.8367 0.1109 0.3759 0.6492 0.0585 0.1611 0.0374 0.8166 0.1990 0.6694 0.2990 0.7443 0.8442 0.0041 0.6524 0.9627 0.7393 Columns 757 through 774 0.8983 0 0.1113 0.6808 0.9299 0.1535 0.6016 0.1187 0.3504 0.7327 0.3666 0.7187 0.5493 0.6797 0.8573 0.1837 0.7295 0 Columns 775 through 792 0.5451 0.1822 0.4916 0.3036 0.6988 0 0.6310 0.3699 0.6706 0.4281 0.5207 0.9507 0.8501 0.8074 0.4442 0.0957 0.1542 0.9919 Columns 793 through 810 0.3159 0.3833 0.5790 0.6613 0.6544 0.4924 0.4653 0.1238 0.5635 0 0.3597 0.5651 0.8194 0.6122 0.6204 0.7396 0.4793 0.6038 Columns 811 through 828 0.3521 0.9396 0.7893 0.7111 0.2324 0.8617 0.7748 0.3565 0.0264 0.6462 0.1880 0.5225 0.1800 0.3664 0.9229 0.3452 0.0150 0.8774 Columns 829 through 846 0.4554 0.8166 0.4412 0.5039 0.6442 0.6298 0.9422 0.4540 0.1682 0.1293 0.3264 0.6505 0.9125 0.8715 0.6299 0.4304 0.3931 0.2036 Columns 847 through 864 0.8624 0.3201 0.9518 0.5404 0.4456 0.8173 0.1890 0.5595 0.6491 0.8758 0.0123 0.2958 0.5317 0.3505 0.1235 0.6...

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

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