Cody

# Problem 1482. Number of cyles and fixed points in a permutation

Solution 1049322

Submitted on 9 Nov 2016
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
x = [3 4 5 7 6 1 8 2]; y_correct = 2; assert(isequal(number_of_cycles(x),y_correct))

2   Pass
x = [2 3 4 1 5 6]; y_correct = 3; assert(isequal(number_of_cycles(x),y_correct))

3   Pass
x = [1]; y_correct = 1; assert(isequal(number_of_cycles(x),y_correct))

4   Pass
x = [1 2]; y_correct = 2; assert(isequal(number_of_cycles(x),y_correct))

5   Fail
x = [2 1]; y_correct = 1; assert(isequal(number_of_cycles(x),y_correct))

Error using matlab.internal.graph.MLGraph Duplicate edges not supported. Error in matlab.internal.graph.constructFromEdgeList (line 125) G = underlyingCtor(double(s), double(t), totalNodes); Error in graph (line 264) matlab.internal.graph.constructFromEdgeList(... Error in number_of_cycles (line 2) n = max(conncomp(graph(perm, perm(perm)))); Error in TestPoint5 (line 3) assert(isequal(number_of_cycles(x),y_correct))

6   Pass
x = [4 5 7 6 8 2 1 3]; y_correct = 1; assert(isequal(number_of_cycles(x),y_correct))

7   Pass
x = [4 2 7 6 5 8 1 3]; y_correct = 3; assert(isequal(number_of_cycles(x),y_correct))

8   Fail
x = [3 4 1 2 6 5]; y_correct = 3; assert(isequal(number_of_cycles(x),y_correct))

Error using matlab.internal.graph.MLGraph Duplicate edges not supported. Error in matlab.internal.graph.constructFromEdgeList (line 125) G = underlyingCtor(double(s), double(t), totalNodes); Error in graph (line 264) matlab.internal.graph.constructFromEdgeList(... Error in number_of_cycles (line 2) n = max(conncomp(graph(perm, perm(perm)))); Error in TestPoint8 (line 3) assert(isequal(number_of_cycles(x),y_correct))

9   Fail
x = [3 4 1 2 6 5 8 9 7]; y_correct = 4; assert(isequal(number_of_cycles(x),y_correct))

Error using matlab.internal.graph.MLGraph Duplicate edges not supported. Error in matlab.internal.graph.constructFromEdgeList (line 125) G = underlyingCtor(double(s), double(t), totalNodes); Error in graph (line 264) matlab.internal.graph.constructFromEdgeList(... Error in number_of_cycles (line 2) n = max(conncomp(graph(perm, perm(perm)))); Error in TestPoint9 (line 3) assert(isequal(number_of_cycles(x),y_correct))

10   Fail
x = [3 4 1 2 6 5 8 9 7 10]; y_correct = 5; assert(isequal(number_of_cycles(x),y_correct))

Error using matlab.internal.graph.MLGraph Duplicate edges not supported. Error in matlab.internal.graph.constructFromEdgeList (line 125) G = underlyingCtor(double(s), double(t), totalNodes); Error in graph (line 264) matlab.internal.graph.constructFromEdgeList(... Error in number_of_cycles (line 2) n = max(conncomp(graph(perm, perm(perm)))); Error in TestPoint10 (line 3) assert(isequal(number_of_cycles(x),y_correct))

11   Pass
x = [3 4 2 5 1 8 9 7 10 6]; y_correct = 2; assert(isequal(number_of_cycles(x),y_correct))

12   Pass
x = [3 4 2 5 1 8 9 7 10 6 11]; y_correct = 3; assert(isequal(number_of_cycles(x),y_correct))