Cody

# Problem 21. Return the 3n+1 sequence for n

Solution 2098877

Submitted on 19 Jan 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   Fail
n = 1; c_correct = 1; assert(isequal(collatz(n),c_correct))

x = 1 i = 1 pos = 2 i = 21 c = 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 pos = 2 c = 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 c = 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 c = 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 c = 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 c = 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 c = 1 0 0 0 0 0 0 0 0 0 0 0 0 0 c = 1 0 0 0 0 0 0 0 0 0 0 0 0 c = 1 0 0 0 0 0 0 0 0 0 0 0 c = 1 0 0 0 0 0 0 0 0 0 0 c = 1 0 0 0 0 0 0 0 0 0 c = 1 0 0 0 0 0 0 0 0 c = 1 0 0 0 0 0 0 0 c = 1 0 0 0 0 0 0 c = 1 0 0 0 0 0 c = 1 0 0 0 0 c = 1 0 0 0 c = 1 0 0 c = 1 0 c = 1

Matrix index is out of range for deletion. Error in collatz (line 28) c(pos)=[] Error in Test1 (line 3) assert(isequal(collatz(n),c_correct))

2   Fail
n = 2; c_correct = [2 1]; assert(isequal(collatz(n),c_correct))

x = 2 i = 1 pos = 2 c = 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 x = 1 c = 2 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 i = 20 pos = 3 i = 21 pos = 4 pos = 4 c = 2 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 c = 2 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 c = 2 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 c = 2 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 c = 2 1 0 0 0 0 0 0 0 0 0 0 0 0 0 c = 2 1 0 0 0 0 0 0 0 0 0 0 0 0 c = 2 1 0 0 0 0 0 0 0 0 0 0 0 c = 2 1 0 0 0 0 0 0 0 0 0 0 c = 2 1 0 0 0 0 0 0 0 0 0 c = 2 1 0 0 0 0 0 0 0 0 c = 2 1 0 0 0 0 0 0 0 c = 2 1 0 0 0 0 0 0 c = 2 1 0 0 0 0 0 c = 2 1 0 0 0 0 c = 2 1 0 0 0 c = 2 1 0 0 c = 2 1 0

Matrix index is out of range for deletion. Error in collatz (line 28) c(pos)=[] Error in Test2 (line 3) assert(isequal(collatz(n),c_correct))

3   Fail
n = 5; c_correct = [5 16 8 4 2 1]; assert(isequal(collatz(n),c_correct))

x = 5 i = 1 pos = 2 c = 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 x = 16 i = 2 pos = 3 c = 5 16 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 x = 8 i = 3 pos = 4 c = 5 16 8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 x = 4 i = 4 pos = 5 c = 5 16 8 4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 x = 2 i = 5 pos = 6 c = 5 16 8 4 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 x = 1 c = 5 16 8 4 2 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 i = 20 pos = 7 i = 21 pos = 8 pos = 8 c = 5 16 8 4 2 1 0 0 0 0 0 0 0 0 0 0 0 0 0 c = 5 16 8 4 2 1 0 0 0 0 0 0 0 0 0 0 0 0 c = 5 16 8 4 2 1 0 0 0 0 0 0 0 0 0 0 0 c = 5 16 8 4 2 1 0 0 0 0 0 0 0 0 0 0 c = 5 16 8 4 2 1 0 0 0 0 0 0 0 0 0 c = 5 16 8 4 2 1 0 0 0 0 0 0 0 0 c = 5 16 8 4 2 1 0 0 0 0 0 0 0 c = 5 16 8 4 2 1 0 0 0 0 0 0 c = 5 16 8 4 2 1 0 0 0 0 0 c = 5 16 8 4 2 1 0 0 0 0 c = 5 16 8 4 2 1 0 0 0 c = 5 16 8 4 2 1 0 0 c = 5 16 8 4 2 1 0

Matrix index is out of range for deletion. Error in collatz (line 28) c(pos)=[] Error in Test3 (line 3) assert(isequal(collatz(n),c_correct))

4   Fail
n = 22; c_correct = [22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1]; assert(isequal(collatz(n),c_correct))

x = 22 i = 1 pos = 2 c = 22 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 x = 11 i = 2 pos = 3 c = 22 11 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 x = 34 i = 3 pos = 4 c = 22 11 34 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 x = 17 i = 4 pos = 5 c = 22 11 34 17 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 x = 52 i = 5 pos = 6 c = 22 11 34 17 52 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 x = 26 i = 6 pos = 7 c = 22 11 34 17 52 26 0 0 0 0 0 0 0 0 0 0 0 0 0 0 x = 13 i = 7 pos = 8 c = 22 11 34 17 52 26 13 0 0 0 0 0 0 0 0 0 0 0 0 0 x = 40 i = 8 pos = 9 c = 22 11 34 17 52 26 13 40 0 0 0 0 0 0 0 0 0 0 0 0 x = 20 i = 9 pos = 10 c = 22 11 34 17 52 26 13 40 20 0 0 0 0 0 0 0 0 0 0 0 x = 10 i = 10 pos = 11 c = 22 11 34 17 52 26 13 40 20 10 0 0 0 0 0 0 0 0 0 0 x = 5 i = 11 pos = 12 c = 22 11 34 17 52 26 13 40 20 10 5 0 0 0 0 0 0 0 0 0 x = 16 i = 12 pos = 13 c = 22 11 34 17 52 26 13 40 20 10 5 16 0 0 0 0 0 0 0 0 x = 8 i = 13 pos = 14 c = 22 11 34 17 52 26 13 40 20 10 5 16 8 0 0 0 0 0 0 0 x = 4 i = 14 pos = 15 c = 22 11 34 17 52 26 13 40 20 10 5 16 8 4 0 0 0 0 0 0 x = 2 i = 15 pos = 16 c = 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 0 0 0 0 0 x = 1 c = 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1 0 0 0 0 i = 20 pos = 17 i = 21 pos = 18 pos = 18 c = 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1 0 0 0 c = 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1 0 0 c = 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1 0

Matrix index is out of range for deletion. Error in collatz (line 28) c(pos)=[] Error in Test4 (line 3) assert(isequal(collatz(n),c_correct))