Cody

# Problem 45470. Count the number of reaction chains achievable in T mins

Solution 3539625

Submitted on 4 Nov 2020
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

filetext = 'function y = reaction_chain2(R,S,T) m = zeros(max([R(:,1);R(:,2)])); for index = 1:size(R,1) if m(R(index,1),R(index,2)) == 0 m(R(index,1),R(index,2)) = R(index,3); else m(R(index,1),R(index,2)) = min([R(index,3) m(R(index,1),R(index,2))]); end end g = digraph(m); d = distances(g); y = sum(d(S,:) <= T); end %This code written by profile_id 18732036 '

2   Fail
R = [1 2 1.5; 1 3 2.5; 2 3 0.6; 3 4 4.1; 4 2 3.2]; assert(isequal(reaction_chain2(R,1,5),3)) assert(isequal(reaction_chain2(R,1,10),6))

Assertion failed.

3   Fail
R = [2 1 1.5592;1 2 2.4465;7 6 5.9819;7 6 1.9563;5 7 4.9169; ... 9 10 2.6206;9 10 3.6554;10 9 6.9576;2 1 1.5000;2 13 9.0677; ... 13 2 7.3477;4 5 8.9883;5 4 7.8082;6 5 0.7312;10 8 2.5875; ... 8 9 4.9516;10 9 3.9300;12 1 0.0830;1 12 9.7302;13 12 6.0841; ... 3 5 0.0807;3 5 5.3663;4 5 2.4256;7 9 0.1973;7 9 8.2272; ... 8 9 1.6038;11 12 8.2550;13 11 1.9458;13 11 1.3879;2 4 9.8468; ... 3 2 4.8237;2 3 5.5103;7 6 9.9712;7 8 5.0623;7 6 8.8766; ... 11 12 4.6054;10 12 1.0703;10 12 5.3461;3 2 5.4698;1 2 5.6282; ... 2 1 2.9354;7 6 1.5597;6 5 8.5908;5 7 7.9862;9 11 5.0525; ... 9 11 3.1038;11 10 2.6583]; assert(isequal(reaction_chain2(R,4,100),1966)) assert(isequal(reaction_chain2(R,2,3),3)) assert(isequal(reaction_chain2(R,1,20),74))

Assertion failed.

4   Fail
R = [3 2 8.2070;2 1 1.0576;5 6 4.3201;5 6 1.1111;6 7 5.3338; ... 11 10 9.7877;10 11 5.9987;9 10 4.3743;14 13 2.7591;13 15 8.6333; ... 14 13 5.6640;17 18 1.6193;17 1 2.8767;17 18 6.9178;4 3 5.6304; ... 4 3 4.3412;5 4 0.5619;9 8 9.5380;9 7 0.0224;9 8 7.1412; ... 11 13 2.7473;11 12 0.6646;12 11 1.2049;17 15 8.9250;16 15 3.4592; ... 17 15 0.4951;1 2 4.0666;1 2 0.5611;2 3 6.7063;6 5 2.7088; ... 5 7 7.1288;5 6 0.6856;11 9 4.1500;11 10 5.9775;9 10 8.3965; ... 15 14 7.5966;14 15 4.1755;14 13 8.3002;1 18 5.0146;1 17 9.7139; ... 17 18 0.2792;3 5 5.4500;5 3 2.3200;5 3 8.7088;7 8 4.0699; ... 8 7 1.8611;9 8 7.8793;13 11 7.7952;11 13 5.4524;13 12 1.3119]; assert(isequal(reaction_chain2(R,16,30),42)) assert(isequal(reaction_chain2(R,16,20),9)) assert(isequal(reaction_chain2(R,16,10),1))

Assertion failed.

5   Fail
R = [2 3 3.1864;3 2 4.9359;1 2 7.7339;5 1 5.2448;2 5 1.3431; ... 4 1 4.8876;4 1 9.5712;4 1 2.6840;4 3 0.0273;5 4 1.7028; ... 5 4 5.2548;3 2 4.2046;3 4 8.6170;3 4 9.1101;2 1 3.3861]; assert(isequal(reaction_chain2(R,1,20),8)) assert(isequal(reaction_chain2(R,3,11),14)) assert(isequal(reaction_chain2(R,3,12),18)) assert(isequal(reaction_chain2(R,3,13),20)) assert(isequal(reaction_chain2(R,3,14),23)) assert(isequal(reaction_chain2(R,3,15),24)) assert(isequal(reaction_chain2(R,3,100),44))

Assertion failed.

6   Fail
R = [4 16 0.4237;2 9 0.0306;8 11 0.6388;1 13 0.1693;2 16 0.3843; ... 8 6 0.5554;6 7 0.3490;17 7 0.1930;17 6 0.5509;17 2 0.2577; ... 8 11 0.8995;4 18 0.4340;15 10 0.3313;8 13 0.9162;17 3 0.1199; ... 17 12 0.0403;10 17 0.3857;6 5 0.2009;7 11 0.2684;12 15 0.1040; ... 14 12 0.4747;17 2 0.5991;5 1 0.5799;16 11 0.8399;4 12 0.1740; ... 6 1 0.7015;18 14 0.7567;10 6 0.2449;6 18 0.2307;10 4 0.4340; ... 3 7 0.7936;15 17 0.5404;15 13 0.0432;3 5 0.2467;4 5 0.2755; ... 18 7 0.2973;8 6 0.7573;7 3 0.6172;16 9 0.0776;17 6 0.6139; ... 12 4 0.9600;12 10 0.8690;11 1 0.4827;15 14 0.5723;1 13 0.4494; ... 12 14 0.8047;1 15 0.5674;2 5 0.1335;11 10 0.0689;18 5 0.3155; ... 6 1 0.5279;5 8 0.9475;17 3 0.5919]; assert(isequal(reaction_chain2(R,9,100),0)) assert(isequal(reaction_chain2(R,3,100),3812)) assert(isequal(reaction_chain2(R,3,1),4)) assert(isequal(reaction_chain2(R,3,2),42))

Assertion failed.

7   Fail
R = [1 2 5;1 2 9]; assert(isequal(reaction_chain2(R,1,10),2)) assert(isequal(reaction_chain2(R,2,10),0))

Assertion failed.

8   Fail
R = [3 1 9.1338;2 1 2.7850;1 2 9.6489;5 2 9.5717;1 2 1.4189; ... 5 1 7.9221;1 5 0.3571;5 4 7.0605;3 5 6.9483;3 5 0.3445; ... 5 3 4.8976;4 2 6.7970;3 2 1.1900;3 4 3.4039;2 1 7.5127; ... 1 2 6.9908;3 1 8.1428;5 2 3.4998;5 2 7.5373]; assert(isequal(reaction_chain2(R,4,7),1)) assert(isequal(reaction_chain2(R,1,5),3))

Assertion failed.

9   Fail
R = [3 1 3.9978;1 3 4.3141;7 5 2.6380;7 6 3.5095;5 6 0.4965; ... 10 9 7.8025;10 9 4.0391;1 10 0.5978;3 4 8.2119;4 5 6.4775; ... 5 3 6.8678;7 8 6.2562;9 7 9.2939;9 8 4.3586;2 1 5.0851; ... 2 3 7.9483;3 2 6.2248;6 5 3.0125;6 5 8.4431]; assert(isequal(reaction_chain2(R,2,23),21)) assert(isequal(reaction_chain2(R,2,25),25))

Assertion failed.

10   Fail
R = [1 2 3.1110;3 2 1.8482;6 5 6.0284;7 5 1.1742;6 5 2.6248; ... 11 9 9.2885;11 10 5.7853;9 10 9.6309;13 15 9.1329;15 13 2.6187; ... 14 15 1.3655;4 2 6.5376;3 4 7.1504;4 2 0.3054;8 7 4.7992; ... 8 7 6.1767;6 7 1.6793;11 10 6.8197;10 12 8.1755;12 10 6.5961; ... 15 1 6.4899;1 15 4.3239]; assert(isequal(reaction_chain2(R,3,30),4)) assert(isequal(reaction_chain2(R,12,30),1)) assert(isequal(reaction_chain2(R,6,30),4))

Assertion failed.

### Community Treasure Hunt

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

Start Hunting!