Cody

Solution 551866

Submitted on 4 Jan 2015 by Andrei Bobrov
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
%% test 1 nterms = 10; term0 = randi(10); increment = (-1)^randi(2)*randi(10); correctsequence = term0:increment:term0+(nterms-1)*increment; for position = 1:nterms errorsequence = correctsequence; errorsequence(position) = errorsequence(position) + (-1)^randi(2)*randi(50); [errorposition, truesequence] = find_error(errorsequence); assert(errorposition == position && isequal(truesequence, correctsequence), 'failed test 1 at position %d', position); end

d = -16 -1 -1 -1 -1 -1 -1 -1 -1 ii = -1 ans = 1 q = 1 d = 34 -36 -1 -1 -1 -1 -1 -1 -1 ii = -1 ans = 1 2 q = 1 2 d = -1 25 -27 -1 -1 -1 -1 -1 -1 ii = -1 ans = 2 3 q = 2 3 d = -1 -1 38 -40 -1 -1 -1 -1 -1 ii = -1 ans = 3 4 q = 3 4 d = -1 -1 -1 -11 9 -1 -1 -1 -1 ii = -1 ans = 4 5 q = 4 5 d = -1 -1 -1 -1 -7 5 -1 -1 -1 ii = -1 ans = 5 6 q = 5 6 d = -1 -1 -1 -1 -1 -7 5 -1 -1 ii = -1 ans = 6 7 q = 6 7 d = -1 -1 -1 -1 -1 -1 -27 25 -1 ii = -1 ans = 7 8 q = 7 8 d = -1 -1 -1 -1 -1 -1 -1 -32 30 ii = -1 ans = 8 9 q = 8 9 d = -1 -1 -1 -1 -1 -1 -1 -1 20 ii = -1 ans = 9 q = 9

2   Pass
%%test 2 nterms = 201; term0 = randi(10); increment = (-1)^randi(2)*randi(10); correctsequence = term0:increment:term0+(nterms-1)*increment; for position = 1:10:nterms errorsequence = correctsequence; errorsequence(position) = errorsequence(position) + (-1)^randi(2)*randi(50); [errorposition, truesequence] = find_error(errorsequence); assert(errorposition == position && isequal(truesequence, correctsequence), 'failed test 2 at position %d', position); end

d = Columns 1 through 16 -30 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 Columns 17 through 32 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 Columns 33 through 48 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 Columns 49 through 64 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 Columns 65 through 80 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 Columns 81 through 96 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 Columns 97 through 112 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 Columns 113 through 128 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 Columns 129 through 144 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 Columns 145 through 160 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 Columns 161 through 176 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 Columns 177 through 192 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 Columns 193 through 200 -8 -8 -8 -8 -8 -8 -8 -8 ii = -8 ans = 1 q = 1 d = Columns 1 through 16 -8 -8 -8 -8 -8 -8 -8 -8 -8 10 -26 -8 -8 -8 -8 -8 Columns 17 through 32 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 Columns 33 through 48 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 Columns 49 through 64 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 Columns 65 through 80 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 Columns 81 through 96 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 Columns 97 through 112 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 Columns 113 through 128 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 Columns 129 through 144 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 Columns 145 through 160 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 Columns 161 through 176 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 Columns 177 through 192 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 Columns 193 through 200 -8 -8 -8 -8 -8 -8 -8 -8 ii = -8 ans = 10 11 q = 10 11 d = Columns 1 through 16 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 Columns 17 through 32 -8 -8 -8 -52 36 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 Columns 33 through 48 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 Columns 49 through 64 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 Columns 65 through 80 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 Columns 81 through 96 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 Columns 97 through 112 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 Columns 113 through 128 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 Columns 129 through 144 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 Columns 145 through 160 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 Columns 161 through 176 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 Columns 177 through 192 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 Columns 193 through 200 -8 -8 -8 -8 -8 -8 -8 -8 ii = -8 ans = 20 21 q = 20 21 d = Columns 1 through 16 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 Columns 17 through 32 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -47 31 -8 Columns 33 through 48 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 Columns 49 through 64 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 Columns 65 through 80 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 Columns 81 through 96 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 Columns 97 through 112 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 Columns 113 through 128 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 Columns 129 through 144 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 Columns 145 through 160 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 Columns 161 through 176 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 Columns 177 through 192 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 Columns 193 through 200 -8 -8 -8 -8 -8 -8 -8 -8 ii = -8 ans = 30 31 q = 30 31 d = Columns 1 through 16 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 Columns 17 through 32 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 Columns 33 through 48 -8 -8 -8 -8 -8 -8 -8 21 -37 -8 -8 -8 -8 -8 -8 -8 Columns 49 through 64 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 Columns 65 through 80 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 Columns 81 through 96 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 Columns 97 through 112 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 Columns 113 through 128 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 Columns 129 through 144 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 Columns 145 through 160 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 Columns 161 through 176 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 Columns 177 through 192 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 Columns 193 through 200 -8 -8 -8 -8 -8 -8 -8 -8 ii = -8 ans = 40 41 q = 40 41 d = Columns 1 through 16 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 Columns 17 through 32 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 Columns 33 through 48 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 Columns 49 through 64 -8 -26 10 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 Columns 65 through 80 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 Columns 81 through 96 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 Columns 97 through 112 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 Columns 113 through 128 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 Columns 129 through 144 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 Columns 145 through 160 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 Columns 161 through 176 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 Columns 177 through 192 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 Columns 193 through 200 -8 -8 -8 -8 -8 -8 -8 -8 ii = -8 ans = 50 51 q = 50 51 d = Columns 1 through 16 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 Columns 17 through 32 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 Columns 33 through 48 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 Columns 49 through 64 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 7 -23 -8 ...

Suggested Problems

More from this Author9