MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn moreOpportunities for recent engineering grads.

Apply TodayCorrect

36Size

This is the leading solution.
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

1 player likes this solution

Test

Code Input and Output

1

Pass

%% dependencies = [ 0 0 1 0 ]; order = calculation_order(dependencies); order_correct = [ 1 2 ]; assert(isequal(order_correct,order));

2

Pass

%% dependencies = [ 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 1 1 1 0 ]; order = calculation_order(dependencies); order_correct = sortrows([ 2 1 4 3 5 ; 2 1 3 4 5 ]); assert(isequal(order_correct,order));

3

Pass

%% dependencies = [ 0 1 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 1 1 1 0 ]; order = calculation_order(dependencies); assert(isequal([],order));

4

Pass

%% dependencies = [ 0 1 1 1 1 0 0 1 1 1 0 0 0 1 1 0 0 0 0 1 0 0 0 0 0 ]; order = calculation_order(dependencies); ordered = dependencies(order,order); assert(~nnz(triu(ordered-diag(diag(ordered)))));

5

Pass

%% dependencies_ = [ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 ]; order_ = randperm(size(dependencies_,1)); dependencies = dependencies_(order_,order_); order_ = 0; order = calculation_order(dependencies); assert(isequal(size(unique(order,'rows'),1),30)); for ii = 1:size(order,1) ordered = dependencies(order(ii,:),order(ii,:)); assert(~nnz(triu(ordered-diag(diag(ordered))))); end

1 Comment