Cody

Problem 1998. Bleed non-zeros to the right

Solution 367398

Submitted on 10 Dec 2013 by Akshay Rawal
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')

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

y = Columns 1 through 5 0.0000 + 0.0000i 0.0000 + 0.0000i -12.0000 + 0.0000i 13.0000 + 0.0000i 13.0000 + 0.0000i Columns 6 through 10 0.0000 + 1.0000i 0.0000 + 1.0000i 0.0000 - 1.0000i 76.5432 + 0.0000i 76.5432 + 0.0000i Column 11 76.5432 + 0.0000i

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

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

y = Columns 1 through 10 0.2342 0.9375 0.2855 0.2855 0.2324 0.2801 0.0102 0.0102 0.6669 0.3206 Columns 11 through 20 0.8892 0.7976 0.9320 0.4172 0.1006 0.7827 0.8089 0.3521 0.9853 0.1263 Columns 21 through 30 0.9475 0.8991 0.0607 0.7048 0.1689 0.0745 0.7291 0.4428 0.3912 0.2335 Columns 31 through 40 0.1586 0.3106 0.4602 0.7311 0.9410 0.7712 0.0178 0.5077 0.4544 0.3666 Columns 41 through 50 0.7484 0.1124 0.4875 0.8642 0.1508 0.4784 0.0388 0.9456 0.1523 0.0406 Columns 51 through 60 0.8955 0.0915 0.2432 0.6790 0.2884 0.4764 0.0634 0.4658 0.6415 0.7723 Columns 61 through 70 0.5994 0.7336 0.7897 0.1866 0.7720 0.0193 0.3207 0.1987 0.4150 0.4150 Columns 71 through 80 0.9432 0.9175 0.6680 0.2517 0.2202 0.2409 0.5876 0.9591 0.9957 0.4556 Columns 81 through 90 0.6235 0.6235 0.8342 0.8720 0.1082 0.8990 0.7763 0.5123 0.7570 0.1667 Columns 91 through 100 0.1667 0.1749 0.7111 0.0294 0.1082 0.1206 0.4003 0.2326 0.8942 0.0038 Columns 101 through 110 0.2150 0.2902 0.4444 0.9864 0.8723 0.3655 0.1943 0.8473 0.8380 0.8235 Columns 111 through 120 0.2057 0.5562 0.4262 0.7840 0.5771 0.8983 0.8504 0.3099 0.0778 0.8852 Columns 121 through 130 0.7210 0.6340 0.7956 0.7956 0.4899 0.5429 0.2501 0.9289 0.0830 0.7798 Columns 131 through 140 0.0013 0.4277 0.3149 0.4364 0.4197 0.6960 0.1440 0.7808 0.1068 0.1798 Columns 141 through 150 0.1748 0.7964 0.6819 0.4918 0.8451 0.7622 0.5966 0.6017 0.3689 0.1269 Columns 151 through 160 0.9927 0.0226 0.7174 0.7174 0.7846 0.7846 0.6669 0.9249 0.1057 0.8850 Columns 161 through 170 0.4365 0.1705 0.9100 0.5209 0.0634 0.9412 0.0360 0.7732 0.7604 0.2122 Columns 171 through 180 0.6845 0.9588 0.0881 0.5588 0.1754 0.4159 0.8820 0.0830 0.0607 0.4979 Columns 181 through 190 0.8359 0.8359 0.8542 0.2081 0.9862 0.5621 0.6909 0.4308 0.9188 0.4701 Columns 191 through 200 0.6498 0.3713 0.0695 0.1959 0.3001 0.8614 0.2391 0.1363 0.4461 0.4461 Columns 201 through 210 0.6274 0.2918 0.0196 0.6776 0.2632 0.2632 0.8938 0.7325 0.5686 0.4375 Columns 211 through 220 0.8210 0.2690 0.2915 0.4051 0.4415 0.3391 0.1318 0.6692 0.6966 0.4666 Columns 221 through 230 0.0726 0.7689 0.6059 0.6536 0.8910 0.8910 0.8256 0.5568 0.6960 0.1957 Columns 231 through 240 0.9033 0.4360 0.1504 0.4301 0.2114 0.8821 0.1819 0.3908 0.7557 0.4629 Columns 241 through 250 0.5410 0.2047 0.8214 0.6414 0.9894 0.3705 0.5519 0.0791 0.0805 0.3366 Columns 251 through 260 0.9264 0.1862 0.7224 0.8305 0.8043 0.2578 0.1949 0.8992 0.3170 0.8083 Columns 261 through 270 0.7132 0.8869 0.1899 0.1899 0.2282 0.9922 0.2141 0.8877 0.1312 0.0442 Columns 271 through 280 0.6531 0.4592 0.9468 0.6313 0.7093 0.1179 0.5457 0.9626 0.4235 0.0539 Columns 281 through 290 0.6264 0.7967 0.9789 0.1876 0.8164 0.3820 0.1923 0.7117 0.4945 0.5193 Columns 291 through 300 0.5552 0.7174 0.6079 0.2649 0.9476 0.5655 0.8757 0.7237 0.7069 0.0713 Columns 301 through 310 0.8328 0.4647 0.3399 0.1001 0.5781 0.8739 0.7106 0.8583 0.2422 0.1433 Columns 311 through 320 0.9612 0.6615 0.5984 0.5274 0.1987 0.7310 0.2540 0.3049 0.2719 0.4097 Columns 321 through 330 0.8757 0.6619 0.5013 0.5013 0.6040 0.0647 0.0230 0.7451 0.7175 0.4477 Columns 331 through 340 0.6642 0.6655 0.1006 0.3986 0.7012 0.7353 0.2920 0.3751 0.8165 0.2633 Columns 341 through 350 0.0350 0.6527 0.5651 0.3045 0.2782 0.5845 0.1817 0.6108 0.0341 0.0959 Columns 351 through 360 0.2998 0.1594 0.3582 0.3582 0.3435 0.3805 0.8761 0.8547 0.5163 0.6574 Columns 361 through 370 0.2559 0.5976 0.1494 0.8174 0.2623 0.7337 0.5621 0.9488 0.6009 0.1142 Columns 371 through 380 0.9920 0.3302 0.0765 0.1896 0.7884 0.7884 0.9924 0.6326 0.9057 0.9057 Columns 381 through 390 0.3561 0.1882 0.9132 0.3918 0.3329 0.8088 0.3084 0.0567 0.8934 0.3490 Columns 391 through 400 0.3200 0.0201 0.5722 0.5347 0.0349 0.6203 0.5692 0.2032 0.0946 0.5228 Columns 401 through 410 0.4223 0.9707 0.0867 0.0467 0.3792 0.3792 0.2759 0.7569 0.5887 0.3562 Columns 411 through 420 0.2705 0.4403 0.4359 0.5143 0.5300 0.0048 0.6379 0.1848 0.6525 0.4233 Columns 421 through 430 0.6433 0.3220 0.6169 0.5692 0.4160 0.3963 0.9651 0.8713 0.1085 0.9007 Columns 431 through 440 0.4721 0.7840 0.7179 0.1839 0.4794 0.6364 0.2898 0.4936 0.3829 0.1623 Columns 441 through 450 0.0930 0.8898 0.3768 0.3768 0.1334 0.1232 0.2320 0.2320 0.6768 0.9720 Columns 451 through 460 0.6464 0.3961 0.9148 0.5445 0.9566 0.8464 0.5723 0.3170 0.2669 0.3759 Columns 461 through 470 0.4224 0.8189 0.8891 0.0403 0.9632 0.8205 0.6346 0.3583 0.5890 0.1421 Columns 471 through 480 0.4172 0.6285 0.7434 0.8766 0.3862 0.0699 0.4855 0.0128 0.9665 0.9665 Columns 481 through 490 0.8713 0.6170 0.6699 0.6699 0.2625 0.2716 0.4522 0.8422 0.5378 0.0790 Columns 491 through 500 0.1063 0.5350 0.2171 0.3144 0.5884 0.7188 0.6587 0.5963 0.6386 0.8121 Columns 501 through 510 0.7674 0.4702 0.2118 0.9683 0.3321 0.4033 0.7827 0.1017 0.4660 0.7327 Columns 511 through 520 0.0417 0.5672 0.5281 0.0621 0.8102 0.2663 0.2897 0.2897 0.4600 0.5316 Columns 521 through 530 0.2631 0.3118 0.0714 0.7307 0.1153 0.1193 0.8397 0.8397 0.0387 0.9360 Columns 531 through 540 0.1945 0.1945 0.3012 0.4480 0.0929 0.0329 0.1951 0.5382 0.9685 0.6374 Columns 541 through 550 0.0996 0.8004 0.5186 0.3895 0.6711 0.6711 0.1087 0.3827 0.2394 0.3250 Columns 551 through 560 0.7857 0.7857 0.7645 0.6450 0.1657 0.4267 0.4483 0.0861 0.8787 0.8794 Columns 561 through 570 0.4051 0.4004 0.1603 0.4707 0.1320 0.2669 0.5877 0.2295 0.7658 0.3376 Columns 571 through 580 0.3200 0.6556 0.9890 0.7504 0.1569 0.1828 0.8588 0.3825 0.0436 0.3685 Columns 581 through 590 0.7089 0.6625 0.3857 0.8215 0.3905 0.9180 0.6676 0.0012 0.0919 0.0728 Columns 591 through 600 0.4943 0.5360 0.1174 0.4611 0.0328 0.8589 0.0917 0.4718 0.3003 0.7492 Columns 601 through 610 0.8985 0.5913 0.8164 0.3957 0.0411 0.7990 0.4254 0.5258 0.8286 0.2807 Columns 611 through 620 0.0155 0.4301 0.3336 0.6117 0.4515 0.0679 0.3809 0.8964 0.4567 0.3319 Columns 621 through 630 0.8502 0.9945 0.8863 0.5618 0.9968 0.5124 0.1582 0.1662 0.7212 0.0599 Columns 631 through 640 0.2262 0.2262 0.7881 0.3441 0.9116 0.9099 0.5721 0.2334 0.9268 0.9426 Columns 641 through 650 0.0017 0.3902 0.7734 0.6179 0.3987 0.0142 0.8570 0.8628 0.2280 0.1844 Columns 651 through 660 0.7616 0.0046 0.6033 0.9336 0.7112 0.6692 0.2780 0.7734 0.2552 0.4907 Columns 661 through 670 0.9519 0.9647 0.5686 0.2507 0.6194 0.7032 0.9369 0.6528 0.2288 0.2430 Columns 671 through 680 0.5944 0.8261 0.7731 0.1215 0.0456 0.1332 0.2659 0.3640 0.3583 0.0174 Columns 681 through 690 0.0468 0.2749 0.9713 0.5531 0.5783 0.7966 0.8399 0.8879 0.8407 0.4042 Columns 691 through 700 0.1745 0.2382 0.2326 0.2326 0.5872 0.6643 0.7011 0.7011 0.0537 0.3900 Columns 701 through 710 0.7644 0.0436 0.3504 0.7773 0.5034 0.1144 0.8585 0.1275 0.5742 0.2421 Columns 711 through 720 0.5816 0.4941 0.8675 0.2784 0.8228 0.4978 0.3389 0.1333 0.2018 0.3627 Columns 721 through 730 0.4656 0.3627 0.2790 0.2790 0.1781 0.0212 0.6734 0.5241 0.0039 0.4501 Columns 731 through 740 0.4793 0.4793 0.8118 0.6734 0.0009 0.0229 0.4151 0.5281 0.1012 0.3676 Columns 741 through 750 0.5373 0.0817 0.4013 0.0369 0.7076 0.9078 0.1145 0.6012 0.8576 0.6777 Columns 751 through 760 0.1151 0.6657 0.8224 0.8224 0.0118 0.0118 0.9568 0.4455 0.4604 0.2697 Columns 761 through 770 0.3272 0.4471 0.5265 0.0855 0.3698 0.0405 0.3811 0.7704 0.0834 0.8991 Columns 771 through 780 0.1617 0.3838 0.0560 0.0823 0.8852 0.0817 0.9254 0.9254 0.5924 0.5924 Columns 781 through 790 0.0060 0.4741 0.0274 0.2354 0.4214 0.0560 0.6776 0.7809 ...

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

y = Columns 1 through 16 1 1 1 2 2 2 2 2 3 3 3 3 3 3 3 4 Columns 17 through 32 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 Columns 33 through 48 5 5 5 6 6 6 6 6 6 6 6 6 6 6 6 6 Columns 49 through 64 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 8 Columns 65 through 80 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 Columns 81 through 96 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 Columns 97 through 100 9 9 9 10

Suggested Problems

More from this Author31

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!