Cody

# Problem 139. Determine if a Given Number is a Triangle Number

Solution 1123769

Submitted on 15 Feb 2017 by mohammad z
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
x = 1:100; y_correct = false(1,100); y_correct([1 3 6 10 15 21 28 36 45 55 66 78 91]) = true; assert(isequal(isTriangleNumber(x),y_correct))

t = 3 y = 1 t = 4.1231 y = 1 0 t = 5 y = 1 0 1 t = 5.7446 y = 1 0 1 0 t = 6.4031 y = 1 0 1 0 0 t = 7 y = 1 0 1 0 0 1 t = 7.5498 y = 1 0 1 0 0 1 0 t = 8.0623 y = 1 0 1 0 0 1 0 0 t = 8.5440 y = 1 0 1 0 0 1 0 0 0 t = 9 y = 1 0 1 0 0 1 0 0 0 1 t = 9.4340 y = 1 0 1 0 0 1 0 0 0 1 0 t = 9.8489 y = 1 0 1 0 0 1 0 0 0 1 0 0 t = 10.2470 y = 1 0 1 0 0 1 0 0 0 1 0 0 0 t = 10.6301 y = 1 0 1 0 0 1 0 0 0 1 0 0 0 0 t = 11 y = 1 0 1 0 0 1 0 0 0 1 0 0 0 0 1 t = 11.3578 y = 1 0 1 0 0 1 0 0 0 1 0 0 0 0 1 0 t = 11.7047 y = Columns 1 through 16 1 0 1 0 0 1 0 0 0 1 0 0 0 0 1 0 Column 17 0 t = 12.0416 y = Columns 1 through 16 1 0 1 0 0 1 0 0 0 1 0 0 0 0 1 0 Columns 17 through 18 0 0 t = 12.3693 y = Columns 1 through 16 1 0 1 0 0 1 0 0 0 1 0 0 0 0 1 0 Columns 17 through 19 0 0 0 t = 12.6886 y = Columns 1 through 16 1 0 1 0 0 1 0 0 0 1 0 0 0 0 1 0 Columns 17 through 20 0 0 0 0 t = 13 y = Columns 1 through 16 1 0 1 0 0 1 0 0 0 1 0 0 0 0 1 0 Columns 17 through 21 0 0 0 0 1 t = 13.3041 y = Columns 1 through 16 1 0 1 0 0 1 0 0 0 1 0 0 0 0 1 0 Columns 17 through 22 0 0 0 0 1 0 t = 13.6015 y = Columns 1 through 16 1 0 1 0 0 1 0 0 0 1 0 0 0 0 1 0 Columns 17 through 23 0 0 0 0 1 0 0 t = 13.8924 y = Columns 1 through 16 1 0 1 0 0 1 0 0 0 1 0 0 0 0 1 0 Columns 17 through 24 0 0 0 0 1 0 0 0 t = 14.1774 y = Columns 1 through 16 1 0 1 0 0 1 0 0 0 1 0 0 0 0 1 0 Columns 17 through 25 0 0 0 0 1 0 0 0 0 t = 14.4568 y = Columns 1 through 16 1 0 1 0 0 1 0 0 0 1 0 0 0 0 1 0 Columns 17 through 26 0 0 0 0 1 0 0 0 0 0 t = 14.7309 y = Columns 1 through 16 1 0 1 0 0 1 0 0 0 1 0 0 0 0 1 0 Columns 17 through 27 0 0 0 0 1 0 0 0 0 0 0 t = 15 y = Columns 1 through 16 1 0 1 0 0 1 0 0 0 1 0 0 0 0 1 0 Columns 17 through 28 0 0 0 0 1 0 0 0 0 0 0 1 t = 15.2643 y = Columns 1 through 16 1 0 1 0 0 1 0 0 0 1 0 0 0 0 1 0 Columns 17 through 29 0 0 0 0 1 0 0 0 0 0 0 1 0 t = 15.5242 y = Columns 1 through 16 1 0 1 0 0 1 0 0 0 1 0 0 0 0 1 0 Columns 17 through 30 0 0 0 0 1 0 0 0 0 0 0 1 0 0 t = 15.7797 y = Columns 1 through 16 1 0 1 0 0 1 0 0 0 1 0 0 0 0 1 0 Columns 17 through 31 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 t = 16.0312 y = Columns 1 through 16 1 0 1 0 0 1 0 0 0 1 0 0 0 0 1 0 Columns 17 through 32 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 t = 16.2788 y = Columns 1 through 16 1 0 1 0 0 1 0 0 0 1 0 0 0 0 1 0 Columns 17 through 32 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 Column 33 0 t = 16.5227 y = Columns 1 through 16 1 0 1 0 0 1 0 0 0 1 0 0 0 0 1 0 Columns 17 through 32 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 Columns 33 through 34 0 0 t = 16.7631 y = Columns 1 through 16 1 0 1 0 0 1 0 0 0 1 0 0 0 0 1 0 Columns 17 through 32 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 Columns 33 through 35 0 0 0 t = 17 y = Columns 1 through 16 1 0 1 0 0 1 0 0 0 1 0 0 0 0 1 0 Columns 17 through 32 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 Columns 33 through 36 0 0 0 1 t = 17.2337 y = Columns 1 through 16 1 0 1 0 0 1 0 0 0 1 0 0 0 0 1 0 Columns 17 through 32 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 Columns 33 through 37 0 0 0 1 0 t = 17.4642 y = Columns 1 through 16 1 0 1 0 0 1 0 0 0 1 0 0 0 0 1 0 Columns 17 through 32 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 Columns 33 through 38 0 0 0 1 0 0 t = 17.6918 y = Columns 1 through 16 1 0 1 0 0 1 0 0 0 1 0 0 0 0 1 0 Columns 17 through 32 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 Columns 33 through 39 0 0 0 1 0 0 0 t = 17.9165 y = Columns 1 through 16 1 0 1 0 0 1 0 0 0 1 0 0 0 0 1 0 Columns 17 through 32 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 Columns 33 through 40 0 0 0 1 0 0 0 0 t = 18.1384 y = Columns 1 through 16 1 0 1 0 0 1 0 0 0 1 0 0 0 0 1 0 Columns 17 through 32 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 Columns 33 through 41 0 0 0 1 0 0 0 0 0 t = 18.3576 y = Columns 1 through 16 1 0 1 0 0 1 0 0 0 1 0 0 0 0 1 0 Columns 17 through 32 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 Columns 33 through 42 0 0 0 1 0 0 0 0 0 0 t = 18.5742 y = Columns 1 through 16 1 0 1 0 0 1 0 0 0 1 0 0 0 0 1 0 Columns 17 through 32 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 Columns 33 through 43 0 0 0 1 0 0 0 0 0 0 0 t = 18.7883 y = Columns 1 through 16 1 0 1 0 0 1 0 0 0 1 0 0 0 0 1 0 Columns 17 through 32 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 Columns 33 through 44 0 0 0 1 0 0 0 0 0 0 0 0 t = 19 y = Columns 1 through 16 1 0 1 0 0 1 0 0 0 1 0 0 0 0 1 0 Columns 17 through 32 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 Columns 33 through 45 0 0 0 1 0 0 0 0 0 0 0 0 1 t = 19.2094 y = Columns 1 through 16 1 0 1 0 0 1 0 0 0 1 0 0 0 0 1 0 Columns 17 through 32 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 Columns 33 through 46 0 0 0 1 0 0 0 0 0 0 0 0 1 0 t = 19.4165 y = Columns 1 through 16 1 0 1 0 0 1 0 0 0 1 0 0 0 0 1 0 Columns 17 through 32 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 Columns 33 through 47 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 t = 19.6214 y = Columns 1 through 16 1 0 1 0 0 1 ...

2   Pass
x = 1; y_correct = true; assert(isequal(isTriangleNumber(x),y_correct))

t = 3 y = 1

3   Pass
x = [4912734125;4912734126]; y_correct = [false;true]; assert(isequal(isTriangleNumber(x),y_correct))

y = 0 1