Cody

# Problem 1771. Polygonal numbers

Solution 2059021

Submitted on 16 Dec 2019
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
assert(P(4,3)==9)

a = 1 b = 1 y = 9

2   Pass
s=3; n=1:5; y_correct=[1 3 6 10 15]; assert(isequal(P(s,n),y_correct))

a = 1 b = 5 y = 1 3 6 10 15

3   Fail
s=3:6; n=4; Y_correct=[10 16 22 28]; assert(isequal(P(s,n),Y_correct))

a = 4 b = 1 y = 10 y = 10 16 y = 10 16 22 y = 10 16 22 28

Assertion failed.

4   Fail
s=randi([3 1000],1,10); n=1; y_correct=ones(1,10); assert(isequal(P(s,n),y_correct))

a = 10 b = 1 y = 1 y = 1 1 y = 1 1 1 y = 1 1 1 1 y = 1 1 1 1 1 y = 1 1 1 1 1 1 y = 1 1 1 1 1 1 1 y = 1 1 1 1 1 1 1 1 y = 1 1 1 1 1 1 1 1 1 y = 1 1 1 1 1 1 1 1 1 1

Assertion failed.

5   Fail
s=randi(1000,1,10)+2; n=5; y_correct=10*s-15; assert(isequal(P(s,n),y_correct))

a = 10 b = 1 y = 4245 y = 4245 325 y = 4245 325 7255 y = 4245 325 7255 2005 y = 4245 325 7255 2005 5685 y = 4245 325 7255 2005 5685 825 y = 4245 325 7255 2005 5685 825 6785 y = 4245 325 7255 2005 5685 825 6785 8585 y = 4245 325 7255 2005 5685 825 6785 8585 4675 y = 4245 325 7255 2005 5685 825 6785 8585 4675 4295

Assertion failed.

6   Pass
s=[5 6 7]'; n=[2 8 9]; y_correct=[5 92 117;6 120 153;7 148 189]; assert(isequal(P(s,n),y_correct))

a = 3 b = 3 y = 5 92 117 y = 5 92 117 6 120 153 y = 5 92 117 6 120 153 7 148 189

7   Pass
% for M.Z. s=[5 6 7]'; n=[2 8 9]; y_correct=[5 92 117;6 120 153;7 148 189]; assert(isequal(P(flipud(s),n),flipud(y_correct)))

a = 3 b = 3 y = 7 148 189 y = 7 148 189 6 120 153 y = 7 148 189 6 120 153 5 92 117

8   Pass
s=randi([3,1000]); n=randi([3,1000]); assert(P(s+1,n+1)-P(s,n+1)==P(3,n))

a = 1 b = 1 y = 22223236 a = 1 b = 1 y = 22179576 a = 1 b = 1 y = 43660