Cody

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

Solution 1592937

Submitted on 27 Jul 2018 by Martin C.
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))

y = Columns 1 through 17 2.0000 3.1231 4.0000 4.7446 5.4031 6.0000 6.5498 7.0623 7.5440 8.0000 8.4340 8.8489 9.2470 9.6301 10.0000 10.3578 10.7047 Columns 18 through 34 11.0416 11.3693 11.6886 12.0000 12.3041 12.6015 12.8924 13.1774 13.4568 13.7309 14.0000 14.2643 14.5242 14.7797 15.0312 15.2788 15.5227 Columns 35 through 51 15.7631 16.0000 16.2337 16.4642 16.6918 16.9165 17.1384 17.3576 17.5742 17.7883 18.0000 18.2094 18.4165 18.6214 18.8242 19.0250 19.2237 Columns 52 through 68 19.4206 19.6155 19.8087 20.0000 20.1896 20.3776 20.5639 20.7486 20.9317 21.1133 21.2935 21.4722 21.6495 21.8254 22.0000 22.1733 22.3452 Columns 69 through 85 22.5160 22.6854 22.8537 23.0208 23.1868 23.3516 23.5153 23.6779 23.8395 24.0000 24.1595 24.3180 24.4755 24.6320 24.7876 24.9422 25.0960 Columns 86 through 100 25.2488 25.4008 25.5518 25.7021 25.8514 26.0000 26.1477 26.2947 26.4408 26.5862 26.7308 26.8747 27.0179 27.1603 27.3019 y = 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))

y = 2 y = 1 y = logical 1

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

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