Cody

Solution 891658

Submitted on 19 May 2016 by Atsushi Ueno
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

This solution is outdated. To rescore this solution, sign in.

Test Suite

Test Status Code Input and Output
1   Pass
a=magic(9)-30; b=[sum(a(:,1:3),2) sum(a(:,4:6),2) sum(a(:,7:9),2)]; assert(isequal(matrix_crunch(a),b));

z = 45 84 117 60 3 -54 -21 12 19 65 114 66 9 -48 -24 9 33 30 85 63 6 -51 -27 6 39 63 50 24 12 -45 -21 3 36 60 84 61 -37 -48 -24 0 33 66 90 114 81 -17 -18 6 30 63 87 111 54 20 -6 3 27 60 93 117 60 3 -41 14 33 57 90 114 57 0 -48 -21 25 54 87 120 63 6 -51 -18 -1 y = 84 3 12 114 -48 33 63 -27 63 12 3 84 -48 33 114 -18 63 54 3 93 3 33 114 -48 54 63 -18

2   Pass
a=rand(12); b=[sum(a(:,1:3),2) sum(a(:,4:6),2) sum(a(:,7:9),2) sum(a(:,10:12),2)]; m=matrix_crunch(a); assert(max(max(abs(m-b)))<1e-8)

z = Columns 1 through 9 0.4422 1.0987 1.0737 1.2230 0.9269 1.3243 1.6595 1.7772 1.7965 0.2831 1.1465 1.6967 1.6630 1.5247 1.1154 1.5425 1.7957 1.6863 0.3462 0.6552 0.8739 1.6748 2.2413 2.2479 1.6744 1.5634 1.8916 0.4090 0.9668 1.0949 1.5330 1.7922 1.5636 1.2801 1.1591 2.0363 1.1540 1.8866 1.4781 0.9377 0.4828 1.2227 1.4978 2.1226 2.1978 0.5810 0.6557 1.2836 1.2419 1.7790 1.4101 1.6373 1.3001 1.0359 1.5935 2.5278 1.8359 1.7824 1.4592 1.7769 1.6276 1.5377 1.9199 1.2617 1.8397 1.9227 1.4155 1.0723 0.7807 1.4670 1.4420 1.4260 0.4811 0.8959 1.3807 1.3287 1.7876 1.8851 1.7228 0.9309 0.8980 0.6625 1.1545 1.7702 2.1075 1.7573 1.4167 1.5419 1.4871 1.2379 0.9650 1.4321 2.1929 1.4401 1.9286 1.6267 2.1129 1.6767 1.4912 0.4937 1.1261 0.7850 1.3378 0.9750 1.8783 2.0765 2.0621 1.9440 Columns 10 through 12 1.9394 1.9477 1.1715 1.2979 0.8103 0.6932 1.8233 1.1489 0.3201 2.2647 1.6449 0.6869 2.5786 2.1276 1.1460 0.5136 0.4072 0.3138 1.7906 2.0840 1.1467 0.6968 1.0168 0.5488 1.2832 1.7202 1.0159 0.7358 0.7006 0.4201 1.5385 1.5020 1.0315 1.6747 2.2725 1.4619 y = 1.0987 0.9269 1.7772 1.9477 1.1465 1.5247 1.7957 0.8103 0.6552 2.2413 1.5634 1.1489 0.9668 1.7922 1.1591 1.6449 1.8866 0.4828 2.1226 2.1276 0.6557 1.7790 1.3001 0.4072 2.5278 1.4592 1.5377 2.0840 1.8397 1.0723 1.4420 1.0168 0.8959 1.7876 0.9309 1.7202 1.1545 1.7573 1.4871 0.7006 1.4321 1.9286 1.6767 1.5020 1.1261 0.9750 2.0621 2.2725

3   Pass
a=ones(18); b=3*ones(18,6); assert(isequal(matrix_crunch(a),b))

z = Columns 1 through 16 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 Columns 17 through 18 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 y = 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3

4   Pass
a=magic(15)+j.*flipud(magic(15)); a=a(1:10,:)-rand(10,15); b=[sum(a(:,1:3),2) sum(a(:,4:6),2) sum(a(:,7:9),2) sum(a(:,10:12),2) sum(a(:,13:15),2)]; m=matrix_crunch(a); assert(max(max(abs(m-b)))<1e-8)

z = 1.0e+02 * Columns 1 through 5 2.5986 + 2.2900i 4.1578 + 3.6900i 4.6682 + 4.2000i 5.1779 + 4.7100i 5.6814 + 5.2200i 2.9237 + 2.1200i 4.6344 + 3.3600i 5.1377 + 3.7200i 5.6505 + 4.2300i 6.1644 + 4.7400i 3.2350 + 1.8000i 5.1060 + 2.8800i 5.6194 + 3.2400i 6.1270 + 3.7500i 4.3947 + 4.2600i 3.5517 + 1.6300i 5.5895 + 2.5500i 6.1070 + 2.9100i 4.3684 + 3.2700i 2.6226 + 3.7800i 3.8772 + 1.3100i 6.0676 + 2.0700i 4.3315 + 2.4300i 2.5919 + 2.7900i 0.7051 + 3.3000i 4.1994 + 0.9900i 4.3004 + 1.7400i 2.5599 + 2.1000i 0.8208 + 2.4600i 1.1803 + 2.8200i 2.2761 + 0.6700i 2.5393 + 1.2600i 0.7967 + 1.6200i 1.1574 + 1.9800i 1.5216 + 2.3400i 0.3315 + 0.3500i 0.7602 + 0.7800i 1.2731 + 1.2900i 1.6361 + 1.6500i 1.9884 + 2.0100i 0.6611 + 2.2800i 1.2441 + 2.5500i 1.5984 + 0.8100i 1.9653 + 1.1700i 2.3260 + 1.5300i 0.9871 + 4.2100i 1.7298 + 4.3200i 2.0830 + 2.5800i 2.4418 + 0.8400i 2.8009 + 1.2000i Columns 6 through 10 6.1925 + 5.7300i 4.2963 + 6.2400i 2.4053 + 4.3500i 0.5184 + 2.4600i 1.0358 + 0.5700i 4.4303 + 5.2500i 2.5404 + 5.7600i 0.6503 + 6.1200i 1.0074 + 4.2300i 1.5139 + 2.3400i 2.5074 + 4.7700i 0.6208 + 5.2800i 0.9741 + 5.7900i 1.4868 + 6.1500i 2.0006 + 4.2600i 0.7292 + 4.2900i 1.0912 + 4.8000i 1.4582 + 5.3100i 1.9693 + 5.6700i 2.4785 + 6.0300i 1.0686 + 3.8100i 1.4306 + 4.3200i 1.9379 + 4.8300i 2.4420 + 5.3400i 2.9499 + 5.7000i 1.5399 + 3.3300i 1.9036 + 3.8400i 2.4142 + 4.3500i 2.9247 + 4.8600i 3.4327 + 5.2200i 1.8833 + 2.8500i 2.3923 + 3.3600i 2.8987 + 3.8700i 3.4014 + 4.3800i 3.9134 + 4.8900i 2.3524 + 2.3700i 2.8636 + 2.8800i 3.3789 + 3.3900i 3.8862 + 3.9000i 4.4004 + 4.4100i 2.8385 + 1.8900i 3.3440 + 2.4000i 3.8503 + 2.9100i 4.3559 + 3.4200i 4.8654 + 3.9300i 3.3147 + 1.5600i 3.8196 + 1.9200i 4.3347 + 2.4300i 4.8388 + 2.9400i 5.2031 + 3.4500i Columns 11 through 15 1.5488 + 1.0800i 2.0609 + 1.5900i 2.5672 + 2.1000i 3.0739 + 2.6100i 2.2171 + 1.9100i 2.0240 + 0.6000i 2.5310 + 1.1100i 3.0439 + 1.6200i 3.4068 + 2.1300i 2.3946 + 1.5900i 2.5092 + 2.3700i 3.0153 + 0.6300i 3.5181 + 1.1400i 3.8847 + 1.6500i 2.7087 + 1.2700i 2.9890 + 4.1400i 3.4950 + 2.4000i 3.8553 + 0.6600i 4.2061 + 1.1700i 2.8742 + 0.9500i 3.4641 + 6.0600i 3.9758 + 4.1700i 4.3365 + 2.4300i 4.6993 + 0.6900i 3.2058 + 0.6300i 3.9457 + 5.5800i 4.3022 + 5.9400i 4.6627 + 4.2000i 5.0212 + 2.4600i 3.5170 + 0.3100i 4.4294 + 5.2500i 4.7901 + 5.6100i 5.1428 + 5.9700i 5.4995 + 4.2300i 3.8377 + 2.2400i 4.7560 + 4.7700i 5.1125 + 5.1300i 5.4654 + 5.4900i 5.9825 + 6.0000i 4.1612 + 4.1700i 5.2346 + 4.4400i 5.5977 + 4.8000i 5.9585 + 5.1600i 4.2151 + 5.5200i 2.2297 + 3.8500i 5.5596 + 3.9600i 5.9223 + 4.3200i 4.1830 + 4.6800i 2.4468 + 5.0400i 0.3035 + 3.5300i y = 1.0e+02 * 4.1578 + 3.6900i 5.6814 + 5.2200i 2.4053 + 4.3500i 1.5488 + 1.0800i 3.0739 + 2.6100i 4.6344 + 3.3600i 6.1644 + 4.7400i 0.6503 + 6.1200i 2.0240 + 0.6000i 3.4068 + 2.1300i 5.1060 + 2.8800i 4.3947 + 4.2600i 0.9741 + 5.7900i 2.5092 + 2.3700i 3.8847 + 1.6500i 5.5895 + 2.5500i 2.6226 + 3.7800i 1.4582 + 5.3100i 2.9890 + 4.1400i 4.2061 + 1.1700i 6.0676 + 2.0700i 0.7051 + 3.3000i 1.9379 + 4.8300i 3.4641 + 6.0600i 4.6993 + 0.6900i 4.3004 + 1.7400i 1.1803 + 2.8200i 2.4142 + 4.3500i 3.9457 + 5.5800i 5.0212 + 2.4600i 2.5393 + 1.2600i 1.5216 + 2.3400i 2.8987 + 3.8700i 4.4294 + 5.2500i 5.4995 + 4.2300i 0.7602 + 0.7800i 1.9884 + 2.0100i 3.3789 + 3.3900i 4.7560 + 4.7700i 5.9825 + 6.0000i 1.2441 + 2.5500i 2.3260 + 1.5300i 3.8503 + 2.9100i 5.2346 + 4.4400i 4.2151 + 5.5200i 1.7298 + 4.3200i 2.8009 + 1.2000i 4.3347 + 2.4300i 5.5596 + 3.9600i 2.4468 + 5.0400i