Cody

# Problem 2801. geometric progression

Solution 1906049

Submitted on 20 Aug 2019 by Graham
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) ratio = (-1)^randi(2)*randi(10) correctsequence = term0*ratio.^(0:nterms-1); 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

term0 = 5 ratio = 6 truesequence = -42 -252 -1512 -9072 -54432 -326592 -1959552 -11757312 -70543872 -423263232 truesequence = 30 180 1080 6480 38880 233280 1399680 8398080 50388480 truesequence = 5 30 180 1080 6480 38880 233280 1399680 8398080 50388480 truesequence = 5 30 180 1080 6480 38880 233280 1399680 8398080 50388480 truesequence = 5 30 180 1080 6480 38880 233280 1399680 8398080 50388480 truesequence = 5 30 180 1080 6480 38880 233280 1399680 8398080 50388480 truesequence = 5 30 180 1080 6480 38880 233280 1399680 8398080 50388480 truesequence = 5 30 180 1080 6480 38880 233280 1399680 8398080 50388480 truesequence = 5 30 180 1080 6480 38880 233280 1399680 8398080 50388480 truesequence = 5 30 180 1080 6480 38880 233280 1399680 8398080 50388480 truesequence = 5 30 180 1080 6480 38880 233280 1399680 8398080 50388480 truesequence = 5 30 180 1080 6480 38880 233280 1399680 8398080 50388480

2   Pass
nterms = 15; term0 = randi(10) ratio = (-1)^randi(2)*randi(10) correctsequence = term0*ratio.^(0:nterms-1); 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 2 at position %d', position); end

term0 = 3 ratio = 5 truesequence = 1.0e+11 * -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0002 -0.0008 -0.0039 -0.0195 -0.0977 -0.4883 -2.4414 truesequence = 1.0e+10 * 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0006 0.0029 0.0146 0.0732 0.3662 1.8311 truesequence = 1.0e+10 * 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0006 0.0029 0.0146 0.0732 0.3662 1.8311 truesequence = 1.0e+10 * 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0006 0.0029 0.0146 0.0732 0.3662 1.8311 truesequence = 1.0e+10 * 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0006 0.0029 0.0146 0.0732 0.3662 1.8311 truesequence = 1.0e+10 * 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0006 0.0029 0.0146 0.0732 0.3662 1.8311 truesequence = 1.0e+10 * 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0006 0.0029 0.0146 0.0732 0.3662 1.8311 truesequence = 1.0e+10 * 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0006 0.0029 0.0146 0.0732 0.3662 1.8311 truesequence = 1.0e+10 * 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0006 0.0029 0.0146 0.0732 0.3662 1.8311 truesequence = 1.0e+10 * 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0006 0.0029 0.0146 0.0732 0.3662 1.8311 truesequence = 1.0e+10 * 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0006 0.0029 0.0146 0.0732 0.3662 1.8311 truesequence = 1.0e+10 * 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0006 0.0029 0.0146 0.0732 0.3662 1.8311 truesequence = 1.0e+10 * 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0006 0.0029 0.0146 0.0732 0.3662 1.8311 truesequence = 1.0e+10 * 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0006 0.0029 0.0146 0.0732 0.3662 1.8311 truesequence = 1.0e+10 * 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0006 0.0029 0.0146 0.0732 0.3662 1.8311 truesequence = 1.0e+10 * 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0006 0.0029 0.0146 0.0732 0.3662 1.8311 truesequence = 1.0e+10 * 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0006 0.0029 0.0146 0.0732 0.3662 1.8311