Cody

# Problem 2800. arithmetic progression

Solution 1357079

Submitted on 25 Nov 2017 by Daniel Meier
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

errorposition = 1 errorsequence = 5 13 21 29 37 45 53 61 69 77 errorposition = 2 errorsequence = 5 13 21 29 37 45 53 61 69 77 errorposition = 3 errorsequence = 5 13 21 29 37 45 53 61 69 77 errorposition = 4 errorsequence = 5 13 21 29 37 45 53 61 69 77 errorposition = 5 errorsequence = 5 13 21 29 37 45 53 61 69 77 errorposition = 6 errorsequence = 5 13 21 29 37 45 53 61 69 77 errorposition = 7 errorsequence = 5 13 21 29 37 45 53 61 69 77 errorposition = 8 errorsequence = 5 13 21 29 37 45 53 61 69 77 errorposition = 9 errorsequence = 5 13 21 29 37 45 53 61 69 77 errorposition = 10 errorsequence = 5 13 21 29 37 45 53 61 69 77

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

errorposition = 1 errorsequence = Columns 1 through 15 1 10 19 28 37 46 55 64 73 82 91 100 109 118 127 Columns 16 through 30 136 145 154 163 172 181 190 199 208 217 226 235 244 253 262 Columns 31 through 45 271 280 289 298 307 316 325 334 343 352 361 370 379 388 397 Columns 46 through 60 406 415 424 433 442 451 460 469 478 487 496 505 514 523 532 Columns 61 through 75 541 550 559 568 577 586 595 604 613 622 631 640 649 658 667 Columns 76 through 90 676 685 694 703 712 721 730 739 748 757 766 775 784 793 802 Columns 91 through 105 811 820 829 838 847 856 865 874 883 892 901 910 919 928 937 Columns 106 through 120 946 955 964 973 982 991 1000 1009 1018 1027 1036 1045 1054 1063 1072 Columns 121 through 135 1081 1090 1099 1108 1117 1126 1135 1144 1153 1162 1171 1180 1189 1198 1207 Columns 136 through 150 1216 1225 1234 1243 1252 1261 1270 1279 1288 1297 1306 1315 1324 1333 1342 Columns 151 through 165 1351 1360 1369 1378 1387 1396 1405 1414 1423 1432 1441 1450 1459 1468 1477 Columns 166 through 180 1486 1495 1504 1513 1522 1531 1540 1549 1558 1567 1576 1585 1594 1603 1612 Columns 181 through 195 1621 1630 1639 1648 1657 1666 1675 1684 1693 1702 1711 1720 1729 1738 1747 Columns 196 through 201 1756 1765 1774 1783 1792 1801 errorposition = 11 errorsequence = Columns 1 through 15 1 10 19 28 37 46 55 64 73 82 91 100 109 118 127 Columns 16 through 30 136 145 154 163 172 181 190 199 208 217 226 235 244 253 262 Columns 31 through 45 271 280 289 298 307 316 325 334 343 352 361 370 379 388 397 Columns 46 through 60 406 415 424 433 442 451 460 469 478 487 496 505 514 523 532 Columns 61 through 75 541 550 559 568 577 586 595 604 613 622 631 640 649 658 667 Columns 76 through 90 676 685 694 703 712 721 730 739 748 757 766 775 784 793 802 Columns 91 through 105 811 820 829 838 847 856 865 874 883 892 901 910 919 928 937 Columns 106 through 120 946 955 964 973 982 991 1000 1009 1018 1027 1036 1045 1054 1063 1072 Columns 121 through 135 1081 1090 1099 1108 1117 1126 1135 1144 1153 1162 1171 1180 1189 1198 1207 Columns 136 through 150 1216 1225 1234 1243 1252 1261 1270 1279 1288 1297 1306 1315 1324 1333 1342 Columns 151 through 165 1351 1360 1369 1378 1387 1396 1405 1414 1423 1432 1441 1450 1459 1468 1477 Columns 166 through 180 1486 1495 1504 1513 1522 1531 1540 1549 1558 1567 1576 1585 1594 1603 1612 Columns 181 through 195 1621 1630 1639 1648 1657 1666 1675 1684 1693 1702 1711 1720 1729 1738 1747 Columns 196 through 201 1756 1765 1774 1783 1792 1801 errorposition = 21 errorsequence = Columns 1 through 15 1 10 19 28 37 46 55 64 73 82 91 100 109 118 127 Columns 16 through 30 136 145 154 163 172 181 190 199 208 217 226 235 244 253 262 Columns 31 through 45 271 280 289 298 307 316 325 334 343 352 361 370 379 388 397 Columns 46 through 60 406 415 424 433 442 451 460 469 478 487 496 505 514 523 532 Columns 61 through 75 541 550 559 568 577 586 595 604 613 622 631 640 649 658 667 Columns 76 through 90 676 685 694 703 712 721 730 739 748 757 766 775 784 793 802 Columns 91 through 105 811 820 829 838 847 856 865 874 883 892 901 910 919 928 937 Columns 106 through 120 946 955 964 973 982 991 1000 1009 1018 1027 1036 1045 1054 1063 1072 Columns 121 through 135 1081 1090 1099 1108 1117 1126 1135 1144 1153 1162 1171 1180 1189 1198 1207 Columns 136 through 150 1216 1225 1234 1243 1252 1261 1270 1279 1288 1297 1306 1315 1324 1333 1342 Columns 151 through 165 1351 1360 1369 1378 1387 1396 1405 1414 1423 1432 1441 1450 1459 1468 1477 Columns 166 through 180 1486 1495 1504 1513 1522 1531 1540 1549 1558 1567 1576 1585 1594 1603 1612 Columns 181 through 195 1621 1630 1639 1648 1657 1666 1675 1684 1693 1702 1711 1720 1729 1738 1747 Columns 196 through 201 1756 1765 1774 1783 1792 1801 errorposition = 31 errorsequence = Columns 1 through 15 1 10 19 28 37 46 55 64 73 82 91 100 109 118 127 Columns 16 through 30 136 145 154 163 172 181 190 199 208 217 226 235 244 253 262 Columns 31 through 45 271 280 289 298 307 316 325 334 343 352 361 370 379 388 397 Columns 46 through 60 406 415 424 433 442 451 460 469 478 487 496 505 514 523 532 Columns 61 through 75 541 550 559 568 577 586 595 604 613 622 631 640 649 658 667 Columns 76 through 90 676 685 694 703 712 721 730 739 748 757 766 775 784 793 802 Columns 91 through 105 811 820 829 838 847 856 865 874 883 892 901 910 ...

### Community Treasure Hunt

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

Start Hunting!