Cody

Solution 827345

Submitted on 14 Feb 2016 by Kevin Sharp
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
%% dependencies = [ 0 0 1 0 ]; order = calculation_order(dependencies); order_correct = [ 1 2 ]; assert(isequal(order_correct,order));

i = 1

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

i = 2 i = 1 i = 4 i = 3

3   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)))));

i = 5 i = 4 i = 3 i = 2

4   Pass
%% dependencies_ = tril(randi(2,10)-1); dependencies_ = dependencies_-diag(diag(dependencies_)); order_ = randperm(size(dependencies_,1)); dependencies = dependencies_(order_,order_); clear order_; order = calculation_order(dependencies); % [~,order] = sort(order_); assert(~nnz(triu(dependencies(order,order))));

i = 2 8 10 i = 3 6 7 i = 4 i = 1 5

5   Pass
%% dependencies_ = randi(2,10)-1; dependencies_ = dependencies_-triu(dependencies_); order_ = randperm(size(dependencies_,1)); dependencies = dependencies_(order_,order_); clear order_; % to prevent the evalin hack order = calculation_order(dependencies); % [~,order] = sort(order_); assert(~nnz(triu(dependencies(order,order))));

i = 7 9 i = 5 8 i = 1 i = 2 3 i = 4 10

6   Pass
%% % n = 10; % dependencies_ = tril(randi(3,n)>1|diag(ones(1,n-1),-1))&~eye(n); % order_ = randperm(n); % dependencies = dependencies_(order_,order_); dependencies = [ 0 1 1 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 1 0 0 1 0 0 0 0 1 1 0 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 1 1 1 0 0 0 0 1 1 1 1 1 0 0 1 0 0 0 0 1 1 1 1 1 0 1 0 1 0 1 0 0 0 0 1 0 0 0 0 0 ]; order = calculation_order(dependencies); % [~,order_correct] = sort(order_); order_correct = [ 5 10 2 3 1 8 6 4 9 7 ]; assert(isequal(order,order_correct));

i = 5 i = 10 i = 2 i = 3 i = 1 i = 8 i = 6 i = 4 i = 9