This solution is outdated. To rescore this solution, sign in.
Test | Status | Code Input and Output |
---|---|---|
1 | Pass |
assessFunctionAbsence({'regexp','regexpi','regexprep','str2num','tic','toc','persistent','global','rng','assert','!','system','unix'},'FileName','groupDist.m')
|
2 | Pass |
g = [2 1 3 2 1].';
x = [3 10 15 8 5].';
y_correct = [0 2 5
2 0 7
5 7 0];
assert(isequaln(y_correct,groupDist(x,g)))
|
3 | Pass |
g = [1 2 2].';
x = [0 0
5 12
3 4];
y_correct = [0 5;
5 0];
assert(isequal(y_correct,groupDist(x,g)))
|
4 | Pass |
g = [2 2 3 3 3 1].';
x = [-5 12
3 4
-7 -24
25 4
9 40
0 0];
y_correct = [0 5 25;
5 0 22
25 22 0];
assert(isequal(y_correct,groupDist(x,g)))
|
5 | Pass |
global t
t = zeros(1,3);
rng(923,'twister');
n = 5e3; d = 3; m = 5;
x = rand(n,d);
g = randi(m,n,1);
y_correct = [0,0.00653919638188362,0.00319052186150122,0.00858841434457234,0.00359654235965771
0.00653919638188362,0,0.00855286615862212,0.00589790293838067,0.00484910151004134
0.00319052186150122,0.00855286615862212,0,0.00591041083080696,0.00483607360689871
0.00858841434457234,0.00589790293838067,0.00591041083080696,0,0.00695738487959094
0.00359654235965771,0.00484910151004134,0.00483607360689871,0.00695738487959094,0];
tic, y = groupDist(x,g); t(1) = toc;
assert(isequal(round(y_correct,10),round(y,10)))
|
6 | Pass |
global t
rng(123)
rng(max('cody5'),'combRecursive');
n = 5e3; d = 3; m = 100;
x = 10*rand(n,d);
g = randi(m,n,1);
tic, y = groupDist(x,g); t(2) = toc;
assert(norm(y-y.') < 1e-11 && all(~diag(y)) && all(size(y)==m) && abs(det(y)-0.030846735888559)<1e-8 &&...
abs(cond(y)-1.606720826682107e+04) < 1e-6 && abs(max(nonzeros(y))-1.058563379304832)<1e-10 &&...
abs(mean(nonzeros(y))-0.419901913602729)<1e-8)
|
7 | Pass |
global t
rng(sum('Cody5, Oct. 16, 2017'),'multFibonacci')
n = 5e3; d = 1e2; m = 100;
x = 5*randn(n,d) + 20;
g = randi(m,n,1);
tic, y = groupDist(x,g); t(3) = toc;
assert(norm(y-y.') < 1e-11 && all(~diag(y)) && all(size(y)==m) && ...
abs(cond(y)-2.024633860688276e+02) < 1e-8 && abs(max(nonzeros(y))-57.768463869822135)<1e-10 &&...
abs(mean(nonzeros(y))-53.852605466762945)<1e-8)
|
8 | Pass |
global t
fid = fopen('score.p','Wb');
fwrite(fid,uint8(sscanf([...
'7630312E30307630302E3030000B901C454EFFB100000031000001330000018D483A60'...
'366BC9545F84AE26323B67424D4E8A7A2E5B7D8ACAA45A1C3C5C8B33E245C95243E3CB'...
'AF5D0D993BDA70B7AB5DA365A83E8CA87FFC45265E23EF80943784C5F48E6E53D5DA34'...
'F1F2ECD34683EABE3B7461DC9E8004CC50B2A79D73495F6F625B5365602B2E6C6093D2'...
'997D371DA457CE82327E686AF512A507B2CB62A375BFD1B283DDD2C01EDEF2771EDAA3'...
'6ABB4852BA4061E20149688E812EB41A9AF8627EF35755492D2830EB8718BCFE88027E'...
'6EA960B63A3B3E26E0451B1DCF14F3C20E70D9D93B08E7FF4AE8D82E7CC38042FD38F7'...
'A14D312EF5652823FEB7E8B52AF5C69F5E7D16B116B5F979EDA77459D6BB61B7971A51'...
'041227DD601319D667DF62E8DA5E381FDD07A2806FE835BD2569E5315CDFC19C6B6A2B'...
'4F0FF6BA803F1759ACAB133CCFAB6D5A5D002FC2C5F381F0'],'%2X')));
fclose(fid);
score(round(5*sum(t)))
fprintf('The execution time of test case %d is %.5f seconds \n',[5:7;t])
fprintf('The total execution time is %.5f seconds \n',sum(t))
assert(sum(t)<20, 'Sorry, your solution is too slow. The execution time must not exceed 20 seconds.')
The execution time of test case 5 is 0.53994 seconds
The execution time of test case 6 is 0.54692 seconds
The execution time of test case 7 is 10.78870 seconds
The total execution time is 11.87556 seconds
|
Getting the indices from a vector
3210 Solvers
Right Triangle Side Lengths (Inspired by Project Euler Problem 39)
511 Solvers
1222 Solvers
2622 Solvers
80 Solvers
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!