Cody

# Problem 2800. arithmetic progression

Solution 1951566

Submitted on 28 Sep 2019 by kranthi kumar
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

truesequence = 7 3 -1 -5 -9 -13 -17 -21 -25 -29 errorposition = 1 truesequence = 7 3 -1 -5 -9 -13 -17 -21 -25 -29 errorposition = 2 truesequence = 7 3 -1 -5 -9 -13 -17 -21 -25 -29 errorposition = 3 truesequence = 7 3 -1 -5 -9 -13 -17 -21 -25 -29 errorposition = 4 truesequence = 7 3 -1 -5 -9 -13 -17 -21 -25 -29 errorposition = 5 truesequence = 7 3 -1 -5 -9 -13 -17 -21 -25 -29 errorposition = 6 truesequence = 7 3 -1 -5 -9 -13 -17 -21 -25 -29 errorposition = 7 truesequence = 7 3 -1 -5 -9 -13 -17 -21 -25 -29 errorposition = 8 truesequence = 7 3 -1 -5 -9 -13 -17 -21 -25 -29 errorposition = 9 truesequence = 7 3 -1 -5 -9 -13 -17 -21 -25 -29 errorposition = 10

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

truesequence = Columns 1 through 14 10 18 26 34 42 50 58 66 74 82 90 98 106 114 Columns 15 through 28 122 130 138 146 154 162 170 178 186 194 202 210 218 226 Columns 29 through 42 234 242 250 258 266 274 282 290 298 306 314 322 330 338 Columns 43 through 56 346 354 362 370 378 386 394 402 410 418 426 434 442 450 Columns 57 through 70 458 466 474 482 490 498 506 514 522 530 538 546 554 562 Columns 71 through 84 570 578 586 594 602 610 618 626 634 642 650 658 666 674 Columns 85 through 98 682 690 698 706 714 722 730 738 746 754 762 770 778 786 Columns 99 through 112 794 802 810 818 826 834 842 850 858 866 874 882 890 898 Columns 113 through 126 906 914 922 930 938 946 954 962 970 978 986 994 1002 1010 Columns 127 through 140 1018 1026 1034 1042 1050 1058 1066 1074 1082 1090 1098 1106 1114 1122 Columns 141 through 154 1130 1138 1146 1154 1162 1170 1178 1186 1194 1202 1210 1218 1226 1234 Columns 155 through 168 1242 1250 1258 1266 1274 1282 1290 1298 1306 1314 1322 1330 1338 1346 Columns 169 through 182 1354 1362 1370 1378 1386 1394 1402 1410 1418 1426 1434 1442 1450 1458 Columns 183 through 196 1466 1474 1482 1490 1498 1506 1514 1522 1530 1538 1546 1554 1562 1570 Columns 197 through 201 1578 1586 1594 1602 1610 errorposition = 1 truesequence = Columns 1 through 14 10 18 26 34 42 50 58 66 74 82 90 98 106 114 Columns 15 through 28 122 130 138 146 154 162 170 178 186 194 202 210 218 226 Columns 29 through 42 234 242 250 258 266 274 282 290 298 306 314 322 330 338 Columns 43 through 56 346 354 362 370 378 386 394 402 410 418 426 434 442 450 Columns 57 through 70 458 466 474 482 490 498 506 514 522 530 538 546 554 562 Columns 71 through 84 570 578 586 594 602 610 618 626 634 642 650 658 666 674 Columns 85 through 98 682 690 698 706 714 722 730 738 746 754 762 770 778 786 Columns 99 through 112 794 802 810 818 826 834 842 850 858 866 874 882 890 898 Columns 113 through 126 906 914 922 930 938 946 954 962 970 978 986 994 1002 1010 Columns 127 through 140 1018 1026 1034 1042 1050 1058 1066 1074 1082 1090 1098 1106 1114 1122 Columns 141 through 154 1130 1138 1146 1154 1162 1170 1178 1186 1194 1202 1210 1218 1226 1234 Columns 155 through 168 1242 1250 1258 1266 1274 1282 1290 1298 1306 1314 1322 1330 1338 1346 Columns 169 through 182 1354 1362 1370 1378 1386 1394 1402 1410 1418 1426 1434 1442 1450 1458 Columns 183 through 196 1466 1474 1482 1490 1498 1506 1514 1522 1530 1538 1546 1554 1562 1570 Columns 197 through 201 1578 1586 1594 1602 1610 errorposition = 11 truesequence = Columns 1 through 14 10 18 26 34 42 50 58 66 74 82 90 98 106 114 Columns 15 through 28 122 130 138 146 154 162 170 178 186 194 202 210 218 226 Columns 29 through 42 234 242 250 258 266 274 282 290 298 306 314 322 330 338 Columns 43 through 56 346 354 362 370 378 386 394 402 410 418 426 434 442 450 Columns 57 through 70 458 466 474 482 490 498 506 514 522 530 538 546 554 562 Columns 71 through 84 570 578 586 594 602 610 618 626 634 642 650 658 666 674 Columns 85 through 98 682 690 698 706 714 722 730 738 746 754 762 770 778 786 Columns 99 through 112 794 802 810 818 826 834 842 850 858 866 874 882 890 898 Columns 113 through 126 906 914 922 930 938 946 954 962 970 978 986 994 1002 1010 Columns 127 through 140 1018 1026 1034 1042 1050 1058 1066 1074 1082 1090 1098 1106 1114 1122 Columns 141 through 154 1130 1138 1146 1154 1162 1170 1178 1186 1194 1202 1210 1218 1226 1234 Columns 155 through 168 1242 1250 1258 1266 1274 1282 1290 1298 1306 1314 1322 1330 1338 1346 Columns 169 through 182 1354 1362 1370 1378 1386 1394 1402 1410 1418 1426 1434 1442 1450 1458 Columns 183 through 196 1466 1474 1482 1490 1498 1506 1514 1522 1530 1538 1546 1554 1562 1570 Columns 197 through 201 1578 1586 1594 1602 1610 errorposition = 21 truesequence = Columns 1 through 14 10 18 26 34 42 50 58 66 74 82 90 98 106 114 Columns 15 through 28 122 130 138 146 154 162 170 178 186 194 202 210 218 226 Columns 29 through 42 234 242 250 258 266 274 282 290 298 306 314 322 330 338 Columns 43 through 56 346 354 362 370 378 386 394 402 410 418 426 434 442 450 Columns 57 through 70 458 466 474 482 490 498 506 514 522 530 538 546 554 562 Columns 71 through 84 570 578 586 594 602 610 618 626 634 642 650 658 666 674 Columns 85 through 98 682 690 698 706 714 722 730 738 746 754 762 770 778 786...