Cody

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

Solution 1907531

Submitted on 21 Aug 2019 by Eugene Avrutin
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
n = 1; c_correct = 1; assert(isequal(collatz(n),c_correct))

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

count = 2 y = 2 z = logical 1 p = 2 even = 1 n = 1 c = 2 1

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

count = 2 y = 5 z = logical 0 p = 0 even = 0 n = 16 c = 5 16 count = 3 y = 2 2 2 2 z = 1×4 logical array 1 1 1 1 p = 2 2 2 2 even = 1 n = 8 c = 5 16 8 count = 4 y = 2 2 2 z = 1×3 logical array 1 1 1 p = 2 2 2 even = 1 n = 4 c = 5 16 8 4 count = 5 y = 2 2 z = 1×2 logical array 1 1 p = 2 2 even = 1 n = 2 c = 5 16 8 4 2 count = 6 y = 2 z = logical 1 p = 2 even = 1 n = 1 c = 5 16 8 4 2 1

4   Pass
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))

count = 2 y = 2 11 z = 1×2 logical array 1 0 p = 2 0 even = 1 n = 11 c = 22 11 count = 3 y = 11 z = logical 0 p = 0 even = 0 n = 34 c = 22 11 34 count = 4 y = 2 17 z = 1×2 logical array 1 0 p = 2 0 even = 1 n = 17 c = 22 11 34 17 count = 5 y = 17 z = logical 0 p = 0 even = 0 n = 52 c = 22 11 34 17 52 count = 6 y = 2 2 13 z = 1×3 logical array 1 1 0 p = 2 2 0 even = 1 n = 26 c = 22 11 34 17 52 26 count = 7 y = 2 13 z = 1×2 logical array 1 0 p = 2 0 even = 1 n = 13 c = 22 11 34 17 52 26 13 count = 8 y = 13 z = logical 0 p = 0 even = 0 n = 40 c = 22 11 34 17 52 26 13 40 count = 9 y = 2 2 2 5 z = 1×4 logical array 1 1 1 0 p = 2 2 2 0 even = 1 n = 20 c = 22 11 34 17 52 26 13 40 20 count = 10 y = 2 2 5 z = 1×3 logical array 1 1 0 p = 2 2 0 even = 1 n = 10 c = 22 11 34 17 52 26 13 40 20 10 count = 11 y = 2 5 z = 1×2 logical array 1 0 p = 2 0 even = 1 n = 5 c = 22 11 34 17 52 26 13 40 20 10 5 count = 12 y = 5 z = logical 0 p = 0 even = 0 n = 16 c = 22 11 34 17 52 26 13 40 20 10 5 16 count = 13 y = 2 2 2 2 z = 1×4 logical array 1 1 1 1 p = 2 2 2 2 even = 1 n = 8 c = 22 11 34 17 52 26 13 40 20 10 5 16 8 count = 14 y = 2 2 2 z = 1×3 logical array 1 1 1 p = 2 2 2 even = 1 n = 4 c = 22 11 34 17 52 26 13 40 20 10 5 16 8 4 count = 15 y = 2 2 z = 1×2 logical array 1 1 p = 2 2 even = 1 n = 2 c = 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 count = 16 y = 2 z = logical 1 p = 2 even = 1 n = 1 c = 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1