Cody

# Problem 2800. arithmetic progression

Solution 3737643

Submitted on 19 Nov 2020 by PRM
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 = 3 8 13 18 23 28 33 38 43 48 errorposition = 1 truesequence = 3 8 13 18 23 28 33 38 43 48 errorposition = 2 truesequence = 3 8 13 18 23 28 33 38 43 48 errorposition = 3 truesequence = 3 8 13 18 23 28 33 38 43 48 errorposition = 4 truesequence = 3 8 13 18 23 28 33 38 43 48 errorposition = 5 truesequence = 3 8 13 18 23 28 33 38 43 48 errorposition = 6 truesequence = 3 8 13 18 23 28 33 38 43 48 errorposition = 7 truesequence = 3 8 13 18 23 28 33 38 43 48 errorposition = 8 truesequence = 3 8 13 18 23 28 33 38 43 48 errorposition = 9 truesequence = 3 8 13 18 23 28 33 38 43 48 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 29 8 4 0 -4 -8 -12 -16 -20 -24 -28 -32 -36 -40 -44 -48 -52 -56 -60 -64 -68 -72 -76 -80 -84 -88 -92 -96 -100 -104 Columns 30 through 58 -108 -112 -116 -120 -124 -128 -132 -136 -140 -144 -148 -152 -156 -160 -164 -168 -172 -176 -180 -184 -188 -192 -196 -200 -204 -208 -212 -216 -220 Columns 59 through 87 -224 -228 -232 -236 -240 -244 -248 -252 -256 -260 -264 -268 -272 -276 -280 -284 -288 -292 -296 -300 -304 -308 -312 -316 -320 -324 -328 -332 -336 Columns 88 through 116 -340 -344 -348 -352 -356 -360 -364 -368 -372 -376 -380 -384 -388 -392 -396 -400 -404 -408 -412 -416 -420 -424 -428 -432 -436 -440 -444 -448 -452 Columns 117 through 145 -456 -460 -464 -468 -472 -476 -480 -484 -488 -492 -496 -500 -504 -508 -512 -516 -520 -524 -528 -532 -536 -540 -544 -548 -552 -556 -560 -564 -568 Columns 146 through 174 -572 -576 -580 -584 -588 -592 -596 -600 -604 -608 -612 -616 -620 -624 -628 -632 -636 -640 -644 -648 -652 -656 -660 -664 -668 -672 -676 -680 -684 Columns 175 through 201 -688 -692 -696 -700 -704 -708 -712 -716 -720 -724 -728 -732 -736 -740 -744 -748 -752 -756 -760 -764 -768 -772 -776 -780 -784 -788 -792 errorposition = 1 truesequence = Columns 1 through 29 8 4 0 -4 -8 -12 -16 -20 -24 -28 -32 -36 -40 -44 -48 -52 -56 -60 -64 -68 -72 -76 -80 -84 -88 -92 -96 -100 -104 Columns 30 through 58 -108 -112 -116 -120 -124 -128 -132 -136 -140 -144 -148 -152 -156 -160 -164 -168 -172 -176 -180 -184 -188 -192 -196 -200 -204 -208 -212 -216 -220 Columns 59 through 87 -224 -228 -232 -236 -240 -244 -248 -252 -256 -260 -264 -268 -272 -276 -280 -284 -288 -292 -296 -300 -304 -308 -312 -316 -320 -324 -328 -332 -336 Columns 88 through 116 -340 -344 -348 -352 -356 -360 -364 -368 -372 -376 -380 -384 -388 -392 -396 -400 -404 -408 -412 -416 -420 -424 -428 -432 -436 -440 -444 -448 -452 Columns 117 through 145 -456 -460 -464 -468 -472 -476 -480 -484 -488 -492 -496 -500 -504 -508 -512 -516 -520 -524 -528 -532 -536 -540 -544 -548 -552 -556 -560 -564 -568 Columns 146 through 174 -572 -576 -580 -584 -588 -592 -596 -600 -604 -608 -612 -616 -620 -624 -628 -632 -636 -640 -644 -648 -652 -656 -660 -664 -668 -672 -676 -680 -684 Columns 175 through 201 -688 -692 -696 -700 -704 -708 -712 -716 -720 -724 -728 -732 -736 -740 -744 -748 -752 -756 -760 -764 -768 -772 -776 -780 -784 -788 -792 errorposition = 11 truesequence = Columns 1 through 29 8 4 0 -4 -8 -12 -16 -20 -24 -28 -32 -36 -40 -44 -48 -52 -56 -60 -64 -68 -72 -76 -80 -84 -88 -92 -96 -100 -104 Columns 30 through 58 -108 -112 -116 -120 -124 -128 -132 -136 -140 -144 -148 -152 -156 -160 -164 -168 -172 -176 -180 -184 -188 -192 -196 -200 -204 -208 -212 -216 -220 Columns 59 through 87 -224 -228 -232 -236 -240 -244 -248 -252 -256 -260 -264 -268 -272 -276 -280 -284 -288 -292 -296 -300 -304 -308 -312 -316 -320 -324 -328 -332 -336 Columns 88 through 116 -340 -344 -348 -352 -356 -360 -364 -368 -372 -376 -380 -384 -388 -392 -396 -400 -404 -408 -412 -416 -420 -424 -428 -432 -436 -440 -444 -448 -452 Columns 117 through 145 -456 -460 -464 -468 -472 -476 -480 -484 -488 -492 -496 -500 -504 -508 -512 -516 -520 -524 -528 -532 -536 -540 -544 -548 -552 -556 -560 -564 -568 Columns 146 through 174 -572 -576 -580 -584 -588 -592 -596 -600 -604 -608 -612 -616 -620 -624 -628 -632 -636 -640 -644 -648 -652 -656 -660 -664 -668 -672 -676 -680 -684 Columns 175 through 201 -688 -692 -696 -700 -704 -708 -712 -716 -720 -724 -728 -732 -736 -740 -744 -748 -752 -756 -760 -764 -768 -772 -776 -780 -784 -788 -792 errorposition = 21 truesequence = Columns 1 through 29 8 4 0 -4 -8 -12 -16 -20 -24 -28 -32 -36 -40 -44 -48 -52 -56 -60 -64 -68 -72 -76 -80 -84 -88 -92 -96 -100 -104 Columns 30 through 58 -108 -112 -116 -120 -124 -128 -132 -136 -140 -144 -148 -152 -156 -160 -164 -168 -172 -176 -180 -184 -188 -192 -196 -200 -204 -208 -212 -216 -220 Columns 59 through 87 -224 -228 -232 -236 -240 -244 -248 -252 -256 -260 -264 -268 -272 -276 -280 -284 -288 -292 -296 -300 -304 -308 -312 -316 -320 -324 -328 -332 -336 Columns 88 through 116 -340 -344 -348 -352 -356 -360 -364 -368 -372 -376 -380 -384 -388 -392 -396 -400 -404 -408 -412 -416 -420 -424 -428 -432 -436 -440 -444 -448 -452 Columns 117 through 145 -456 -460 -464 -468 -472 -476 -480 -484 -488 -492 -496 -500 -504 -508 -512 -516 -520 -524 -528 -532 -536 -540 -544 -548 -552 -556 -560 -564 -568 Columns 146 through 174 -572 -576 -580 -584 -588 -592 -596 -600 -604 -608 -612 -616 -620 -624 -628 -632 -636 -640 -644 -648 -652 -656 -660 -664 -668 -672 -676 -680 -684 Columns 175 through 201 -688 -692 -696 -700 -704 -708 -712 -716 -720 -724 -728 -732 -736 -740 -744 -748 -752 -756 -760 -764 -768 -772 -776 -780 -784 -788 -792 errorposition = 31 truesequence = Columns 1 through 29 8 4 0 -4 -8 -12 -16 -20 -24 -28 -32 -36 -40 -44 -48 -52 -56 -60 -64 -68 -72 -76 -80 -84 -88 -92 -96 -100 -104 Columns 30 through 58 -108 -112 -116 -120 -124 -128 -132 -136 -140 -144 -148 -152 -156 -160 -164 -168 -172 -176 -180 -184 -188 -192 -196 -200 -204 -208 -212 -216 -220 Columns 59 through 87 -224 -228 -232 -236 -240 -244 -248 -252 -256 -260 -264 -268 -272 -276 -280 -284 -288 -292 -296 -300 -304 -308 -312 -316 -320 -324 -328 -332 -336 Columns 88 through 116 -340 -344 -348 -352 -356 -360 -364 -368 -372 -376 -380 -384 -388 -392 -396 -400 -404 -408 -412 -416 -420 -424 -428 -432 -436 -440 -444 -448 -452 Columns 117 through 145 -456 -460 -464 -468 -472 -476 -480 -484 -488 -492 -496 -500 -504 -508 -512 -516 -520 -524 -528 -532 -536 -540 -544 -548 -552 -556 -560 -564 -568 Columns 146 through 174 -572 -576 -580 -584 -588 -592 -596 -600 -604 -608 -612 -616 -620 -624 -628 -632 -636 -640 -644 -648 -652 -656 -660 -664 -668 -672 -676 -680 -684 Columns 175 through 201 -688 -692 -696 -700 -704 -708 -712 -716 -720 -724 -728 -732 -736 -740 -744 -748 -752 -756 -760 -764 -768 -772 -776 -780 -784 -788 -792 errorposition = 41 truesequence = Columns 1 through 29 8 4 0 -4 -8 -12 -16 -20 -24 -28 -32 -36 -40 -44 -48 -52 -56 -60 -64 -68 -72 -76 -80 -84 -88 -92 -96 -100 -104 Columns 30 through 58 -108 -112 -116 -120 -124 -128 -132 -136 -140 -144 -148 -152 -156 -160 -164 -168 -172 -176 -180 -184 -188 -192 -196 -200 -204 -208 -212 -216 -220 Columns 59 through 87 -224 -228 -232 -236 -240 -244 -248 -252 -256 -260 -264 -268 -272 -276 -280 -284 -288 -292 -296 -300 -304 -308 -312 -316 -320 -324 -328 -332 -336 Columns 88 through 116 -340 -344 -348 -352 -356 -360 -364 -368 -372 -376 -380 -384 -388 -392 -396 -400 -404 -408 -412 -416 -420 -424 -428 -432 -436 -440 -444 -448 -452 Columns 117 through 145 -456 -460 -464 -468 -472 -476 -480 -484 -488 -492 -496 -500 -504 -508 -512 -516 -520 -524 -528 -532 -536 -540 -544 -548 -552 -556 -560 -564 -568 Columns 146 through 174 -572 -576 -580 -584 -588 -592 -596 -600 -604 -608 -612 -616 -620 -624 -628 -632 -636 -640 -644 -648 -652 -656 -660 -664 -668 -672 -676 -680 -684 Columns 175 through 201 -688 -692 -696 -700 -704 -708 -712 -716 -720 -724 -728 -732 -736 -740 -744 -748 -752 -756 -760 -764 -768 -772 -776 -780 -784 -788 -792 errorposition = 51 truesequence = Columns 1 through 29 8 4 0 -4 -8 -12 -16 -20 -24 -28 -32 -36 -40 -44 -48 -52 -56 -60 -64 -68 -72 -76 -80 -84 -88 -92 -96 -100 -104 Columns 30 through 58 -108 -112 -116 -120 -124 -128 -132 -136 -140 -144 -148 -152 -156 -160 -164 -168 -172 -176 -180 -184 -188 -192 -196 -200 -204 -208 -212 -216 -220 Columns 59 through 87 -224 -228 -232 -236 -240 -244 -248 -252 -256 -260 -264 -268 -272 -276 -280 -284 -288 -292 -296 -300 -304 -308 -312 -316 -320 -324 -328 -332 -336 Columns 88 through 116 -340 -344 -348 -352 -356 -360 -364 -368 -372 -376 -380 -384 -388 -392 -396 -400 -404 -408 -412 -416 -420 -424 -428 -432 -436 -440 -444 -448 -452 Columns 117 through 145 -456 -460 -464 -468 -472 -476 -480 -484 -488 -492 -496 -500 -504 -508 -512 -516 -520 -524 -528 -532 -536 -540 -544 -548 -552 -556 -560 -564 -568 Columns 146 through 174 -572 -576 -580 -584 -588 -592 -596 -600 -604 -608 -612 -616 -620 -624 -628 -632 -636 -640 -644 -648 -652 -656 -660 -664 -668 -672 -676 -680 -684 Columns 175 through 201 -688 -692 -696 -700 -704 -708 -712 -716 -720 -724 -728 -732 -736 -74...

### Community Treasure Hunt

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

Start Hunting!