Cody

Problem 2800. arithmetic progression

Solution 2167482

Submitted on 20 Mar 2020
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   Fail
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

errsq = 47 17 24 31 38 45 52 59 66 73 truesq = 10 17 24 31 38 45 52 59 66 73 err = 1 errsq = 10 31 24 31 38 45 52 59 66 73 truesq = 10 17 24 31 38 45 52 59 66 73 err = 1×0 empty double row vector

Operands to the || and && operators must be convertible to logical scalar values. Error in Test1 (line 9) assert(errorposition == position && isequal(truesequence, correctsequence), 'failed test 1 at position %d', position);

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

errsq = Columns 1 through 15 34 15 21 27 33 39 45 51 57 63 69 75 81 87 93 Columns 16 through 30 99 105 111 117 123 129 135 141 147 153 159 165 171 177 183 Columns 31 through 45 189 195 201 207 213 219 225 231 237 243 249 255 261 267 273 Columns 46 through 60 279 285 291 297 303 309 315 321 327 333 339 345 351 357 363 Columns 61 through 75 369 375 381 387 393 399 405 411 417 423 429 435 441 447 453 Columns 76 through 90 459 465 471 477 483 489 495 501 507 513 519 525 531 537 543 Columns 91 through 105 549 555 561 567 573 579 585 591 597 603 609 615 621 627 633 Columns 106 through 120 639 645 651 657 663 669 675 681 687 693 699 705 711 717 723 Columns 121 through 135 729 735 741 747 753 759 765 771 777 783 789 795 801 807 813 Columns 136 through 150 819 825 831 837 843 849 855 861 867 873 879 885 891 897 903 Columns 151 through 165 909 915 921 927 933 939 945 951 957 963 969 975 981 987 993 Columns 166 through 180 999 1005 1011 1017 1023 1029 1035 1041 1047 1053 1059 1065 1071 1077 1083 Columns 181 through 195 1089 1095 1101 1107 1113 1119 1125 1131 1137 1143 1149 1155 1161 1167 1173 Columns 196 through 201 1179 1185 1191 1197 1203 1209 truesq = Columns 1 through 15 9 15 21 27 33 39 45 51 57 63 69 75 81 87 93 Columns 16 through 30 99 105 111 117 123 129 135 141 147 153 159 165 171 177 183 Columns 31 through 45 189 195 201 207 213 219 225 231 237 243 249 255 261 267 273 Columns 46 through 60 279 285 291 297 303 309 315 321 327 333 339 345 351 357 363 Columns 61 through 75 369 375 381 387 393 399 405 411 417 423 429 435 441 447 453 Columns 76 through 90 459 465 471 477 483 489 495 501 507 513 519 525 531 537 543 Columns 91 through 105 549 555 561 567 573 579 585 591 597 603 609 615 621 627 633 Columns 106 through 120 639 645 651 657 663 669 675 681 687 693 699 705 711 717 723 Columns 121 through 135 729 735 741 747 753 759 765 771 777 783 789 795 801 807 813 Columns 136 through 150 819 825 831 837 843 849 855 861 867 873 879 885 891 897 903 Columns 151 through 165 909 915 921 927 933 939 945 951 957 963 969 975 981 987 993 Columns 166 through 180 999 1005 1011 1017 1023 1029 1035 1041 1047 1053 1059 1065 1071 1077 1083 Columns 181 through 195 1089 1095 1101 1107 1113 1119 1125 1131 1137 1143 1149 1155 1161 1167 1173 Columns 196 through 201 1179 1185 1191 1197 1203 1209 err = 1 errsq = Columns 1 through 15 9 15 21 27 33 39 45 51 57 63 111 75 81 87 93 Columns 16 through 30 99 105 111 117 123 129 135 141 147 153 159 165 171 177 183 Columns 31 through 45 189 195 201 207 213 219 225 231 237 243 249 255 261 267 273 Columns 46 through 60 279 285 291 297 303 309 315 321 327 333 339 345 351 357 363 Columns 61 through 75 369 375 381 387 393 399 405 411 417 423 429 435 441 447 453 Columns 76 through 90 459 465 471 477 483 489 495 501 507 513 519 525 531 537 543 Columns 91 through 105 549 555 561 567 573 579 585 591 597 603 609 615 621 627 633 Columns 106 through 120 639 645 651 657 663 669 675 681 687 693 699 705 711 717 723 Columns 121 through 135 729 735 741 747 753 759 765 771 777 783 789 795 801 807 813 Columns 136 through 150 819 825 831 837 843 849 855 861 867 873 879 885 891 897 903 Columns 151 through 165 909 915 921 927 933 939 945 951 957 963 969 975 981 987 993 Columns 166 through 180 999 1005 1011 1017 1023 1029 1035 1041 1047 1053 1059 1065 1071 1077 1083 Columns 181 through 195 1089 1095 1101 1107 1113 1119 1125 1131 1137 1143 1149 1155 1161 1167 1173 Columns 196 through 201 1179 1185 1191 1197 1203 1209 truesq = Columns 1 through 15 9 15 21 27 33 39 45 51 57 63 69 75 81 87 93 Columns 16 through 30 99 105 111 117 123 129 135 141 147 153 159 165 171 177 183 Columns 31 through 45 189 195 201 207 213 219 225 231 237 243 249 255 261 267 273 Columns 46 through 60 279 285 291 297 303 309 315 321 327 333 339 345 351 357 363 Columns 61 through 75 369 375 381 387 393 399 405 411 417 423 429 435 441 447 453 Columns 76 through 90 459 465 471 477 483 489 495 501 507 513 519 525 531 537 543 Columns 91 through 105 549 555 561 567 573 579 585 591 597 603 609 615 621 627 633 Columns 106 through 120 639 645 651 657 ...

Operands to the || and && operators must be convertible to logical scalar values. Error in Test2 (line 9) assert(errorposition == position && isequal(truesequence, correctsequence), 'failed test 2 at position %d', position);