Cody

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

Solution 3939083

Submitted on 1 Dec 2020 by Akrem Hadji
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 = Columns 1 through 17 1.0000 1.5616 2.0000 2.3723 2.7016 3.0000 3.2749 3.5311 3.7720 4.0000 4.2170 4.4244 4.6235 4.8151 5.0000 5.1789 5.3523 Columns 18 through 34 5.5208 5.6847 5.8443 6.0000 6.1521 6.3007 6.4462 6.5887 6.7284 6.8655 7.0000 7.1322 7.2621 7.3899 7.5156 7.6394 7.7614 Columns 35 through 51 7.8815 8.0000 8.1168 8.2321 8.3459 8.4582 8.5692 8.6788 8.7871 8.8941 9.0000 9.1047 9.2082 9.3107 9.4121 9.5125 9.6119 Columns 52 through 68 9.7103 9.8078 9.9043 10.0000 10.0948 10.1888 10.2819 10.3743 10.4659 10.5567 10.6467 10.7361 10.8248 10.9127 11.0000 11.0866 11.1726 Columns 69 through 85 11.2580 11.3427 11.4269 11.5104 11.5934 11.6758 11.7577 11.8390 11.9197 12.0000 12.0797 12.1590 12.2377 12.3160 12.3938 12.4711 12.5480 Columns 86 through 100 12.6244 12.7004 12.7759 12.8510 12.9257 13.0000 13.0739 13.1473 13.2204 13.2931 13.3654 13.4374 13.5089 13.5801 13.6510 y = 1×100 logical array Columns 1 through 44 1 0 1 0 0 1 0 0 0 1 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 Columns 45 through 88 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 Columns 89 through 100 0 0 1 0 0 0 0 0 0 0 0 0

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

n = 1 y = logical 1

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

n = 1.0e+04 * 9.9123 9.9123 y = 2×1 logical array 0 1


Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!