Cody

# Problem 44338. Recaman Sequence - I

Solution 1960039

Submitted on 4 Oct 2019 by Raymundo Carranza
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 = 1; y_correct = 0; assert(isequal(Recaman(x),y_correct))

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

idx = [] idx = 1×0 empty double row vector idx = 1 idx = 1×0 empty double row vector

3   Pass
x = 8; y_correct = [0 1 3 6 2 7 13 20]; assert(isequal(Recaman(x),y_correct))

idx = [] idx = 1×0 empty double row vector idx = 1 idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 2 idx = 4

4   Pass
x = 10; y_correct = [0 1 3 6 2 7 13 20 12 21]; assert(isequal(Recaman(x),y_correct))

idx = [] idx = 1×0 empty double row vector idx = 1 idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 2 idx = 4 idx = 1×0 empty double row vector idx = 3

5   Pass
x = 5e4; y = Recaman(x); assert(isequal(length(Recaman(x)),x)) assert(isequal(y(954),739)) assert(isequal(y(7589),17654)) assert(isequal(y(12345),18554))

idx = [] idx = 1×0 empty double row vector idx = 1 idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 2 idx = 4 idx = 1×0 empty double row vector idx = 3 idx = 1×0 empty double row vector idx = 1 idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 6 idx = 16 idx = 1×0 empty double row vector idx = 10 idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 7 idx = 31 idx = 1×0 empty double row vector idx = 21 25 idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1 idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 18 idx = 64 idx = 1×0 empty double row vector idx = 58 idx = 1×0 empty double row vector idx = 52 idx = 1×0 empty double row vector idx = 46 idx = 1×0 empty double row vector idx = 36 40 idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 22 idx = 99 idx = 1×0 empty double row vector idx = 93 idx = 1×0 empty double row vector idx = 67 87 idx = 1×0 empty double row vector idx = 73 81 idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 39 idx = 111 idx = 104 idx = 1×0 empty double row vector idx = 110 idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 26 idx = 1×0 empty double row vector idx = 32 idx = 1×0 empty double row vector idx = 11 idx = 1×0 empty double row vector idx = 17 idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 3 idx = 127 131 idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 37 idx = 170 idx = 1×0 empty double row vector idx = 164 idx = 1×0 empty double row vector idx = 158 idx = 1×0 empty double row vector idx = 152 idx = 1×0 empty double row vector idx = 146 idx = 1×0 empty double row vector idx = 140 idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 46 idx = 1×0 empty double row vector idx = 36 40 idx = 102 114 idx = 183 187 idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 22 idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 33 idx = 134 138 222 idx = 1×0 empty double row vector idx = 188 216 idx = 1×0 empty double row vector idx = 106 210 idx = 1×0 empty double row vector idx = 124 204 idx = 1×0 empty double row vector idx = 194 198 idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 24 idx = 1×0 empty double row vector idx = 30 idx = 1×0 empty double row vector idx = 9 idx = 1×0 empty double row vector idx = 15 idx = 1×0 empty double row vector idx = 4 idx = 1×0 empty double row vector idx = 3 idx = 1×0 empty double row vector idx = 1 idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 76 idx = 285 idx = 1×0 empty double row vector idx = 279 idx = 1×0 empty double row v...

6   Pass
x = 1e5; y = Recaman(x); assert(isequal(length(Recaman(x)),x)) assert(isequal(y(1e4),8658)) assert(isequal(y(2e4),34358)) assert(isequal(y(3e4),92474)) assert(isequal(y(4e4),102344))

idx = [] idx = 1×0 empty double row vector idx = 1 idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 2 idx = 4 idx = 1×0 empty double row vector idx = 3 idx = 1×0 empty double row vector idx = 1 idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 6 idx = 16 idx = 1×0 empty double row vector idx = 10 idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 7 idx = 31 idx = 1×0 empty double row vector idx = 21 25 idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1 idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 18 idx = 64 idx = 1×0 empty double row vector idx = 58 idx = 1×0 empty double row vector idx = 52 idx = 1×0 empty double row vector idx = 46 idx = 1×0 empty double row vector idx = 36 40 idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 22 idx = 99 idx = 1×0 empty double row vector idx = 93 idx = 1×0 empty double row vector idx = 67 87 idx = 1×0 empty double row vector idx = 73 81 idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 39 idx = 111 idx = 104 idx = 1×0 empty double row vector idx = 110 idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 26 idx = 1×0 empty double row vector idx = 32 idx = 1×0 empty double row vector idx = 11 idx = 1×0 empty double row vector idx = 17 idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 3 idx = 127 131 idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 37 idx = 170 idx = 1×0 empty double row vector idx = 164 idx = 1×0 empty double row vector idx = 158 idx = 1×0 empty double row vector idx = 152 idx = 1×0 empty double row vector idx = 146 idx = 1×0 empty double row vector idx = 140 idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 46 idx = 1×0 empty double row vector idx = 36 40 idx = 102 114 idx = 183 187 idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 22 idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 33 idx = 134 138 222 idx = 1×0 empty double row vector idx = 188 216 idx = 1×0 empty double row vector idx = 106 210 idx = 1×0 empty double row vector idx = 124 204 idx = 1×0 empty double row vector idx = 194 198 idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 24 idx = 1×0 empty double row vector idx = 30 idx = 1×0 empty double row vector idx = 9 idx = 1×0 empty double row vector idx = 15 idx = 1×0 empty double row vector idx = 4 idx = 1×0 empty double row vector idx = 3 idx = 1×0 empty double row vector idx = 1 idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 1×0 empty double row vector idx = 76 idx = 285 idx = 1×0 empty double row vector idx = 279 idx = 1×0 empty double row v...

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!