Cody

# Problem 2800. arithmetic progression

Solution 1808825

Submitted on 7 May 2019 by Margaret Hoeller
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
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

r = 4 goodind = 2 3 4 5 6 7 8 9 truesequence = 3 7 11 15 19 23 27 31 35 39 r = 4 goodind = 3 4 5 6 7 8 9 truesequence = 3 7 11 15 19 23 27 31 35 39 r = 4 goodind = 1 4 5 6 7 8 9 truesequence = 3 7 11 15 19 23 27 31 35 39 r = 4 goodind = 1 2 5 6 7 8 9 truesequence = 3 7 11 15 19 23 27 31 35 39 r = 4 goodind = 1 2 3 6 7 8 9 truesequence = 3 7 11 15 19 23 27 31 35 39 r = 4 goodind = 1 2 3 4 7 8 9 truesequence = 3 7 11 15 19 23 27 31 35 39 r = 4 goodind = 1 2 3 4 5 8 9 truesequence = 3 7 11 15 19 23 27 31 35 39 r = 4 goodind = 1 2 3 4 5 6 9 truesequence = 3 7 11 15 19 23 27 31 35 39 r = 4 goodind = 1 2 3 4 5 6 7 truesequence = 3 7 11 15 19 23 27 31 35 39 r = 4 goodind = 1 2 3 4 5 6 7 8 truesequence = 3 7 11 15 19 23 27 31 35 39

2   Pass
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

r = 5 goodind = Columns 1 through 30 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 Columns 31 through 60 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 Columns 61 through 90 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 Columns 91 through 120 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 Columns 121 through 150 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 Columns 151 through 180 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 Columns 181 through 199 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 truesequence = Columns 1 through 15 8 13 18 23 28 33 38 43 48 53 58 63 68 73 78 Columns 16 through 30 83 88 93 98 103 108 113 118 123 128 133 138 143 148 153 Columns 31 through 45 158 163 168 173 178 183 188 193 198 203 208 213 218 223 228 Columns 46 through 60 233 238 243 248 253 258 263 268 273 278 283 288 293 298 303 Columns 61 through 75 308 313 318 323 328 333 338 343 348 353 358 363 368 373 378 Columns 76 through 90 383 388 393 398 403 408 413 418 423 428 433 438 443 448 453 Columns 91 through 105 458 463 468 473 478 483 488 493 498 503 508 513 518 523 528 Columns 106 through 120 533 538 543 548 553 558 563 568 573 578 583 588 593 598 603 Columns 121 through 135 608 613 618 623 628 633 638 643 648 653 658 663 668 673 678 Columns 136 through 150 683 688 693 698 703 708 713 718 723 728 733 738 743 748 753 Columns 151 through 165 758 763 768 773 778 783 788 793 798 803 808 813 818 823 828 Columns 166 through 180 833 838 843 848 853 858 863 868 873 878 883 888 893 898 903 Columns 181 through 195 908 913 918 923 928 933 938 943 948 953 958 963 968 973 978 Columns 196 through 201 983 988 993 998 1003 1008 r = 5 goodind = Columns 1 through 30 1 2 3 4 5 6 7 8 9 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 Columns 31 through 60 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 Columns 61 through 90 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 Columns 91 through 120 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 Columns 121 through 150 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 Columns 151 through 180 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 Columns 181 through 198 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 truesequence = Columns 1 through 15 8 13 18 23 28 33 38 43 48 53 58 63 68 73 78 Columns 16 through 30 83 88 93 98 103 108 113 118 123 128 133 138 143 148 153 Columns 31 through 45 158 163 168 173 178 183 188 193 198 203 208 213 218 223 228 Columns 46 through 60 233 238 243 248 253 258 263 268 273 278 283 288 293 298 303 Columns 61 through 75 308 313 318 323 328 333 338 343 348 353 358 363 368 373 378 Columns 76 through 90 383 388 393 398 403 408 413 418 423 428 433 438 443 448 453 Columns 91 through 105 458 463 468 473 478 483 488 493 498 503 508 513 518 523 528 Columns 106 through 120 533 538 543 548 553 558 563 568 573 578 583 588 593 598 603 Columns 121 through 135 608 613 618 623 628 633 638 643 648 653 658 663 668 673 678 Columns 136 through 150 683 688 693 698 703 708 713 718 723 728 733 738 743 748 753 Columns 151 through 165 758 763 768 773 778 783 788 793 798 803 808 813 818 823 828 Columns 166 through 180 833 838 843 848 853 858 863 868 873 878 883 888 893 898 903 Columns 181 through 195 908 913 918 923 928 933 938 943 948 953 958 963 968 973 978 Columns 196 through 201 983 988 993 998 1003 1008 r = 5 goodind = Columns 1 through 30 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 22 23 24 25 26 27 28 29 30 31 32 Columns 31 through 60 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 Columns 61 through 90 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 Columns 91 through 120 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 Columns 121 through 150 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 Columns 151 through 180 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 Columns 181 through 198 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 truesequence = Columns 1 through 15 8 13 18 23 28 33 38 ...