Cody

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

Solution 1870960

Submitted on 10 Jul 2019 by Klap Hest
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))

n = 1 rn = 0 n = 1.5616 rn = 0.5616 n = 2 rn = 0 n = 2.3723 rn = 0.3723 n = 2.7016 rn = 0.7016 n = 3 rn = 0 n = 3.2749 rn = 0.2749 n = 3.5311 rn = 0.5311 n = 3.7720 rn = 0.7720 n = 4 rn = 0 n = 4.2170 rn = 0.2170 n = 4.4244 rn = 0.4244 n = 4.6235 rn = 0.6235 n = 4.8151 rn = 0.8151 n = 5 rn = 0 n = 5.1789 rn = 0.1789 n = 5.3523 rn = 0.3523 n = 5.5208 rn = 0.5208 n = 5.6847 rn = 0.6847 n = 5.8443 rn = 0.8443 n = 6 rn = 0 n = 6.1521 rn = 0.1521 n = 6.3007 rn = 0.3007 n = 6.4462 rn = 0.4462 n = 6.5887 rn = 0.5887 n = 6.7284 rn = 0.7284 n = 6.8655 rn = 0.8655 n = 7 rn = 0 n = 7.1322 rn = 0.1322 n = 7.2621 rn = 0.2621 n = 7.3899 rn = 0.3899 n = 7.5156 rn = 0.5156 n = 7.6394 rn = 0.6394 n = 7.7614 rn = 0.7614 n = 7.8815 rn = 0.8815 n = 8 rn = 0 n = 8.1168 rn = 0.1168 n = 8.2321 rn = 0.2321 n = 8.3459 rn = 0.3459 n = 8.4582 rn = 0.4582 n = 8.5692 rn = 0.5692 n = 8.6788 rn = 0.6788 n = 8.7871 rn = 0.7871 n = 8.8941 rn = 0.8941 n = 9 rn = 0 n = 9.1047 rn = 0.1047 n = 9.2082 rn = 0.2082 n = 9.3107 rn = 0.3107 n = 9.4121 rn = 0.4121 n = 9.5125 rn = 0.5125 n = 9.6119 rn = 0.6119 n = 9.7103 rn = 0.7103 n = 9.8078 rn = 0.8078 n = 9.9043 rn = 0.9043 n = 10 rn = 0 n = 10.0948 rn = 0.0948 n = 10.1888 rn = 0.1888 n = 10.2819 rn = 0.2819 n = 10.3743 rn = 0.3743 n = 10.4659 rn = 0.4659 n = 10.5567 rn = 0.5567 n = 10.6467 rn = 0.6467 n = 10.7361 rn = 0.7361 n = 10.8248 rn = 0.8248 n = 10.9127 rn = 0.9127 n = 11 rn = 0 n = 11.0866 rn = 0.0866 n = 11.1726 rn = 0.1726 n = 11.2580 rn = 0.2580 n = 11.3427 rn = 0.3427 n = 11.4269 rn = 0.4269 n = 11.5104 rn = 0.5104 n = 11.5934 rn = 0.5934 n = 11.6758 rn = 0.6758 n = 11.7577 rn = 0.7577 n = 11.8390 rn = 0.8390 n = 11.9197 rn = 0.9197 n = 12 rn = 0 n = 12.0797 rn = 0.0797 n = 12.1590 rn = 0.1590 n = 12.2377 rn = 0.2377 n = 12.3160 rn = 0.3160 n = 12.3938 rn = 0.3938 n = 12.4711 rn = 0.4711 n = 12.5480 rn = 0.5480 n = 12.6244 rn = 0.6244 n = 12.7004 rn = 0.7004 n = 12.7759 rn = 0.7759 n = 12.8510 rn = 0.8510 n = 12.9257 rn = 0.9257 n = 13 rn = 0 n = 13.0739 rn = 0.0739 n = 13.1473 rn = 0.1473 n = 13.2204 rn = 0.2204 n = 13.2931 rn = 0.2931 n = 13.3654 rn = 0.3654 n = 13.4374 rn = 0.4374 n = 13.5089 rn = 0.5089 n = 13.5801 rn = 0.5801 n = 13.6510 rn = 0.6510 m = 1 n = 100

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

n = 1 rn = 0 m = 1 n = 1

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

n = 9.9123e+04 rn = 1.0000 n = 99123 rn = 0 m = 1 n = 2 y = 2×1 logical array 0 1 0 1